Database Pipes Monitor (vdbpipe.sql)
Database Pipes Monitor
Section titled “Database Pipes Monitor”This script monitors Oracle database pipes used for inter-session communication via the DBMS_PIPE package. It shows pipe ownership, types, and current sizes.
Script: vdbpipe.sql
Section titled “Script: vdbpipe.sql”rem vdbpipe.sqlremttitle 'Database Pipes'remcol owner format a8 heading 'OWNER'col name format a30 heading 'PIPE NAME'col type format a7 heading 'TYPE'col pipe_size format 99999999 heading 'PIPE SIZE'remselect u.username owner, p.name, p.type, p."SIZE" pipe_size from sys.dba_users u, v$db_pipes p where p.ownerid = u.user_id(+) order by u.username, p.name/
What This Script Does
Section titled “What This Script Does”This script provides visibility into Oracle’s database pipe infrastructure by showing:
- Pipe Ownership: Which database user owns each pipe
- Pipe Names: Names of all active database pipes
- Pipe Types: Whether pipes are public or private
- Pipe Sizes: Current size of each pipe in bytes
- System Overview: Complete inventory of inter-session communication channels
-- Monitor all database pipes@vdbpipe.sql
-- Check for specific pipe patternsSELECT username, p.name, p.type, p."SIZE"FROM dba_users u, v$db_pipes pWHERE p.ownerid = u.user_id(+) AND UPPER(p.name) LIKE '%PATTERN%';
Required Privileges
Section titled “Required Privileges”- SELECT privilege on
V$DB_PIPES
- SELECT privilege on
DBA_USERS
- Typically requires DBA role
Sample Output
Section titled “Sample Output” Database Pipes
OWNER PIPE NAME TYPE PIPE SIZE-------- ------------------------------ ------- ---------HR HR_NOTIFICATION_PIPE PRIVATE 1024APPS ORA$_PIPE_GET PUBLIC 2048APPS ORA$_PIPE_PUT PUBLIC 2048SCOTT SCOTT_DEBUG_PIPE PRIVATE 512SYS ALERT_PIPE PUBLIC 4096 ANONYMOUS_PIPE_001 PUBLIC 1024
Key Output Columns
Section titled “Key Output Columns”Column | Description |
---|---|
OWNER | Database user who owns the pipe (NULL for anonymous pipes) |
PIPE NAME | Name of the database pipe |
TYPE | PRIVATE (owner-specific) or PUBLIC (shared) |
PIPE SIZE | Current size of the pipe in bytes |
Understanding Database Pipes
Section titled “Understanding Database Pipes”Pipe Types
Section titled “Pipe Types”Private Pipes:
- Accessible only to the creating user/session
- More secure for sensitive communications
- Automatically cleaned up when user disconnects
Public Pipes:
- Accessible to any database user with appropriate privileges
- Useful for inter-application communication
- Persist until explicitly removed
Common Uses
Section titled “Common Uses”Application Integration:
- Message passing between different applications
- Event notification systems
- Batch job coordination
Debugging and Monitoring:
- Debug message passing
- Application state communication
- Performance monitoring alerts
Common Use Cases
Section titled “Common Use Cases”1. Monitor Application Pipes
Section titled “1. Monitor Application Pipes”-- Check pipes for specific applicationsSELECT u.username, p.name, p.type, p."SIZE", CASE WHEN p."SIZE" > 0 THEN 'HAS_DATA' ELSE 'EMPTY' END as statusFROM dba_users u, v$db_pipes pWHERE p.ownerid = u.user_id(+) AND u.username IN ('APP_USER', 'INTEGRATION_USER')ORDER BY p."SIZE" DESC;
2. Find Large or Busy Pipes
Section titled “2. Find Large or Busy Pipes”-- Identify pipes with dataSELECT u.username, p.name, p.type, p."SIZE"FROM dba_users u, v$db_pipes pWHERE p.ownerid = u.user_id(+) AND p."SIZE" > 0ORDER BY p."SIZE" DESC;
3. Audit Pipe Usage by User
Section titled “3. Audit Pipe Usage by User”-- Count pipes per userSELECT u.username, COUNT(*) as pipe_count, SUM(p."SIZE") as total_size, SUM(CASE WHEN p.type = 'PUBLIC' THEN 1 ELSE 0 END) as public_pipes, SUM(CASE WHEN p.type = 'PRIVATE' THEN 1 ELSE 0 END) as private_pipesFROM dba_users u, v$db_pipes pWHERE p.ownerid = u.user_id(+)GROUP BY u.usernameORDER BY pipe_count DESC;
4. Monitor System Pipes
Section titled “4. Monitor System Pipes”-- Find Oracle system pipesSELECT p.name, p.type, p."SIZE"FROM v$db_pipes pWHERE UPPER(p.name) LIKE 'ORA$%' OR UPPER(p.name) LIKE 'SYS_%'ORDER BY p.name;
Pipe Management Examples
Section titled “Pipe Management Examples”Working with DBMS_PIPE
Section titled “Working with DBMS_PIPE”-- Create a private pipeDECLARE result INTEGER;BEGIN result := DBMS_PIPE.CREATE_PIPE('MY_DEBUG_PIPE', 8192, TRUE); IF result = 0 THEN DBMS_OUTPUT.PUT_LINE('Private pipe created successfully'); END IF;END;/
-- Create a public pipeDECLARE result INTEGER;BEGIN result := DBMS_PIPE.CREATE_PIPE('SHARED_NOTIFICATION_PIPE', 4096, FALSE); IF result = 0 THEN DBMS_OUTPUT.PUT_LINE('Public pipe created successfully'); END IF;END;/
-- Check the new pipes@vdbpipe.sql
Send and Receive Messages
Section titled “Send and Receive Messages”-- Send a messageDECLARE result INTEGER;BEGIN DBMS_PIPE.PACK_MESSAGE('Test message from session 1'); DBMS_PIPE.PACK_MESSAGE(SYSDATE); result := DBMS_PIPE.SEND_MESSAGE('MY_DEBUG_PIPE', 10); DBMS_OUTPUT.PUT_LINE('Send result: ' || result);END;/
-- Receive a message (from another session)DECLARE result INTEGER; message VARCHAR2(4000); msg_date DATE;BEGIN result := DBMS_PIPE.RECEIVE_MESSAGE('MY_DEBUG_PIPE', 10); IF result = 0 THEN DBMS_PIPE.UNPACK_MESSAGE(message); DBMS_PIPE.UNPACK_MESSAGE(msg_date); DBMS_OUTPUT.PUT_LINE('Received: ' || message || ' at ' || msg_date); END IF;END;/
Clean Up Pipes
Section titled “Clean Up Pipes”-- Remove a pipeDECLARE result INTEGER;BEGIN result := DBMS_PIPE.REMOVE_PIPE('MY_DEBUG_PIPE'); IF result = 0 THEN DBMS_OUTPUT.PUT_LINE('Pipe removed successfully'); END IF;END;/
Troubleshooting Pipe Issues
Section titled “Troubleshooting Pipe Issues”1. Check Pipe Permissions
Section titled “1. Check Pipe Permissions”-- Verify user has EXECUTE on DBMS_PIPESELECT grantee, privilege, grantableFROM dba_tab_privsWHERE table_name = 'DBMS_PIPE' AND privilege = 'EXECUTE'ORDER BY grantee;
2. Monitor Pipe Activity
Section titled “2. Monitor Pipe Activity”-- Create monitoring view for pipe changesCREATE OR REPLACE VIEW pipe_monitor ASSELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') as check_time, u.username, p.name, p.type, p."SIZE"FROM dba_users u, v$db_pipes pWHERE p.ownerid = u.user_id(+);
-- Check pipe status over timeSELECT * FROM pipe_monitor ORDER BY check_time DESC;
3. Find Orphaned Pipes
Section titled “3. Find Orphaned Pipes”-- Look for pipes without valid ownersSELECT p.name, p.type, p."SIZE", p.owneridFROM v$db_pipes pWHERE p.ownerid NOT IN (SELECT user_id FROM dba_users) OR p.ownerid IS NULL;
Security Considerations
Section titled “Security Considerations”Pipe Security Review
Section titled “Pipe Security Review”-- Audit pipe securitySELECT CASE WHEN u.username IS NULL THEN 'ANONYMOUS' ELSE u.username END as owner, p.name, p.type, CASE WHEN p.type = 'PUBLIC' AND p."SIZE" > 0 THEN 'SECURITY_REVIEW' WHEN p.name LIKE '%PASSWORD%' OR p.name LIKE '%SECRET%' THEN 'SENSITIVE_NAME' ELSE 'OK' END as security_flagFROM dba_users u, v$db_pipes pWHERE p.ownerid = u.user_id(+)ORDER BY security_flag DESC, u.username;
Best Practices for Pipe Security
Section titled “Best Practices for Pipe Security”- Use Private Pipes for sensitive communications
- Avoid Sensitive Names that reveal pipe purpose
- Regular Cleanup of unused pipes
- Monitor Public Pipes for unauthorized usage
- Limit DBMS_PIPE Access to necessary users only
Integration with Application Monitoring
Section titled “Integration with Application Monitoring”Create Pipe Monitoring Table
Section titled “Create Pipe Monitoring Table”-- Create table for pipe monitoring historyCREATE TABLE pipe_monitoring_log ( log_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, owner_name VARCHAR2(128), pipe_name VARCHAR2(128), pipe_type VARCHAR2(10), pipe_size NUMBER, status VARCHAR2(20));
-- Insert current pipe statusINSERT INTO pipe_monitoring_log (owner_name, pipe_name, pipe_type, pipe_size, status)SELECT NVL(u.username, 'ANONYMOUS'), p.name, p.type, p."SIZE", CASE WHEN p."SIZE" > 0 THEN 'HAS_DATA' ELSE 'EMPTY' ENDFROM dba_users u, v$db_pipes pWHERE p.ownerid = u.user_id(+);
Automated Pipe Alerts
Section titled “Automated Pipe Alerts”-- Create alert for unusual pipe activitySELECT owner_name, pipe_name, pipe_size, 'Large pipe detected' as alert_reasonFROM ( SELECT NVL(u.username, 'ANONYMOUS') as owner_name, p.name as pipe_name, p."SIZE" as pipe_size FROM dba_users u, v$db_pipes p WHERE p.ownerid = u.user_id(+) AND p."SIZE" > 10240 -- Alert for pipes > 10KB)UNION ALLSELECT owner_name, pipe_name, pipe_count, 'Too many pipes for user' as alert_reasonFROM ( SELECT NVL(u.username, 'ANONYMOUS') as owner_name, 'Multiple pipes' as pipe_name, COUNT(*) as pipe_count FROM dba_users u, v$db_pipes p WHERE p.ownerid = u.user_id(+) GROUP BY u.username HAVING COUNT(*) > 5 -- Alert for users with > 5 pipes);
Integration with Other Scripts
Section titled “Integration with Other Scripts”This script works well with:
- Session Analysis (gvsess.sql) - To correlate pipe usage with active sessions
- Database Health Check (db.sql) - For overall system monitoring
- User Analysis (duser.sql) - To understand user privileges related to pipes
Performance Considerations
Section titled “Performance Considerations”Database pipes use shared pool memory, so monitoring them helps with:
- Memory Management: Understanding shared pool usage
- Application Debugging: Tracking inter-session communication
- Performance Tuning: Identifying communication bottlenecks
- Security Auditing: Monitoring data exchange channels
This script provides essential visibility into Oracle’s inter-session communication infrastructure and is particularly valuable for environments using DBMS_PIPE for application integration or custom messaging systems.