Skip to content

SQL*Plus Environment Setup

Set up your SQL*Plus environment to easily access all Oracle Day by Day scripts from any directory.

By configuring your SQLPATH environment variable, you can run any Oracle Day by Day script from anywhere on your system using simple commands like @db.sql instead of typing full file paths.

First, get all the Oracle Day by Day scripts:

Terminal window
# Clone or download the complete script collection
git clone https://github.com/oracledaybyday/oracle-scripts.git
# OR download from: https://oracledaybyday.com/downloads/scripts.zip

Windows (Command Prompt)

Terminal window
# Temporary (current session only)
set SQLPATH=C:\OracleScripts;%SQLPATH%
# Permanent (all sessions)
setx SQLPATH "C:\OracleScripts;%SQLPATH%"

Windows (PowerShell)

Terminal window
# Temporary (current session only)
$env:SQLPATH = "C:\OracleScripts;$env:SQLPATH"
# Permanent (current user)
[Environment]::SetEnvironmentVariable("SQLPATH", "C:\OracleScripts;$env:SQLPATH", "User")

Linux/Unix/macOS

Terminal window
# Add to your ~/.bashrc, ~/.profile, or ~/.zshrc
export SQLPATH="/home/username/OracleScripts:$SQLPATH"
# Reload your shell configuration
source ~/.bashrc

Test that SQL*Plus can find the scripts:

-- Connect to your database
sqlplus username/password@database
-- Test running a script (should work from any directory)
SQL> @db.sql

Organize your Oracle Day by Day scripts in a logical structure:

C:\OracleScripts\ (or /home/username/OracleScripts/)
├── database-info/
│ ├── db.sql
│ ├── gvinst.sql
│ ├── vdb.sql
│ └── ...
├── performance/
│ ├── gvsess.sql
│ ├── gvlock.sql
│ ├── vsqltopfind.sql
│ └── ...
├── administration/
│ ├── gvpga.sql
│ ├── pgmcnt.sql
│ └── ...
└── security/
├── gvpwd.sql
├── role_definitions.sql
└── ...

Once SQLPATH is configured, you can use scripts easily:

Basic Usage

-- Quick database info
SQL> @db.sql
-- Performance analysis
SQL> @gvsess.sql
-- Connection counts
SQL> @pgmcnt.sql

From Any Directory

Terminal window
# You can be in any directory
cd /tmp
sqlplus hr/hr@orcl
SQL> @db.sql -- Still works!
SQL> @gvlock.sql -- Scripts found automatically

Essential database and instance queries

@db.sql -- Quick database overview
@gvinst.sql -- RAC instance status
@varchlog.sql -- Archive log analysis
@vlog.sql -- Redo log status

Performance monitoring and tuning tools

@gvsess.sql -- Active sessions
@gvlock.sql -- Lock analysis
@vsqltopfind.sql -- Top SQL statements
@high_wait_times.sql -- Wait time analysis

DBA maintenance and management utilities

@pgmcnt.sql -- Program connection count
@gvpga.sql -- PGA memory analysis
@gvbp.sql -- Buffer pool statistics

User, role, and privilege management

@gvpwd.sql -- Password verification
@role_definitions.sql -- Role definitions
@vuserall.sql -- User session search

Table, index, and object analysis tools

@dtable.sql -- Table analysis
@dindex.sql -- Index analysis
@qindexddl.sql -- Index DDL generation

Automatic Storage Management utilities

@gvasmdsk.sql -- ASM disk performance
@vasmdsk.sql -- ASM disk status
@vasmdskg.sql -- ASM disk group info

Oracle Enterprise Manager tools

@tablespace_growth_oem.sql -- Tablespace growth tracking

You can include multiple directories in SQLPATH:

Windows

Terminal window
setx SQLPATH "C:\OracleScripts;C:\CustomScripts;C:\TeamScripts"

Linux/Unix/macOS

Terminal window
export SQLPATH="/home/user/OracleScripts:/opt/oracle/scripts:/shared/dba-scripts:$SQLPATH"

Create a login.sql file in your SQLPATH to customize your SQL*Plus environment:

-- login.sql - Executed automatically when SQL*Plus starts
SET PAGESIZE 50
SET LINESIZE 130
SET SERVEROUTPUT ON
SET TIMING ON
SET SQLPROMPT "_USER'@'_CONNECT_IDENTIFIER> "
-- Define common aliases
DEFINE db = "@db.sql"
DEFINE sessions = "@gvsess.sql"
DEFINE locks = "@gvlock.sql"
-- Welcome message
PROMPT
PROMPT Oracle Day by Day Scripts Available
PROMPT Type @db.sql for database info
PROMPT Type @gvsess.sql for active sessions
PROMPT Type @help.sql for script list
PROMPT

Add aliases to your login.sql for frequently used scripts:

-- Quick aliases for common scripts
DEFINE d = "@db.sql"
DEFINE s = "@gvsess.sql"
DEFINE l = "@gvlock.sql"
DEFINE p = "@pgmcnt.sql"
DEFINE t = "@vsqltopfind.sql"
-- Now you can use:
-- SQL> @d (runs db.sql)
-- SQL> @s (runs gvsess.sql)
-- SQL> @l (runs gvlock.sql)

Individual Categories:

Complete Collection:

  • Only add trusted script directories to SQLPATH
  • Review scripts before running in production
  • Use separate script directories for different environments
  • SQL*Plus searches directories in SQLPATH order
  • First match wins - place most important directories first
  • Local directory (.) is searched first by default

Script Not Found

SQL> @mytest.sql
SP2-0310: unable to open file "mytest.sql"
  • Check SQLPATH environment variable: echo %SQLPATH% (Windows) or echo $SQLPATH (Unix)
  • Verify script exists in one of the SQLPATH directories
  • Check file permissions

Environment Variable Not Set

Terminal window
# Check current SQLPATH
echo $SQLPATH
# If empty, verify your shell profile was updated and sourced
source ~/.bashrc