As you already know, an Oracle instance consists of a set of background processes that begin at database startup time and continue to run on the
database server until the database is stopped. These processes constitute the Oracle instance and are the processes that will consume CPU resources on behalf of the Oracle database.
- Binding Oracle Processes to specific CPUs:
In environments where a database server has multiple CPUs, many DBAs have the option of dedicating Oracle processes to run on specific CPUs. This
is an advantage because the Oracle background processes often loose their context when the OS directs the process to use another CPU. The context of a process is the internal instruction set that consists of the CPU registers and their current contents. When an Oracle process switches CPUs, these instruction sets must be moved to the new CPU, slowing down execution time. The implementation details are different for every OS, but in IBMs AIX operating system, process binding is achieved with the bindprocessor UNIX command. Check the Oracle OS-specific documentation for your environment to see how to do process binding in your environment.
These processes are always executing and competing for CPU resources on our database server. In order to check for processes that are consuming an inordinate amount of CPU cycles, you can use the ps command. For example, sometimes Oracle sessions may become disconnected from the database and spin, causing a huge amount of CPU activity. The following example show how to monitor the amount of resources that each process is consuming.
ps -ef | grep ora | sort +6 | tail
The `+6` before the last pipe in your command is considered incorrect in modern versions of the `sort` command.
The `+6` syntax is deprecated and may not work as intended on current UNIX or Linux systems.
What Does the `+6` Indicate?
In older versions of UNIX, the `sort` command used the `+n` syntax to specify the sort field, where `n` is the field number starting from zero. So, `+6` would mean sorting starting from the 7th field (since counting starts at zero).
- Fields in `ps -ef` Output: The `ps -ef` command outputs several columns, typically:
- UID: User ID
- PID: Process ID
- PPID: Parent Process ID
- C: CPU utilization
- STIME: Start time
- TTY: Terminal type
- TIME: Cumulative CPU time
- CMD: Command name and arguments
- Using `+6`: The `+6` tells `sort` to begin sorting from the 7th field (`TIME`), effectively sorting the processes based on their CPU time.
Why Is It Incorrect Now?
- Deprecated Syntax: The `+n` syntax has been deprecated in favor of the `-k` option in modern versions of `sort`.
- Incompatibility: Using `+6` may result in errors or unexpected behavior because newer `sort` implementations do not recognize this syntax.
Correct Syntax with `-k` Option
You should replace `sort +6` with `sort -k7`. The `-k` option specifies the sort key field, and fields are counted starting from 1 in this syntax.
Updated Command:
ps -ef | grep ora | sort -k7 | tail
Explanation:
- `-k7` tells `sort` to use the 7th field (`TIME`) as the sort key.
- This syntax is compatible with modern `sort` versions and is the recommended way to specify sort keys.
Understanding the Full Command
- `ps -ef`: Lists all running processes in a full-format listing.
- `grep ora`: Filters the list to include only lines containing "ora" (commonly associated with Oracle processes).
- `sort -k7`: Sorts the filtered list based on the 7th field (`TIME` column).
- `tail`: Displays the last 10 lines of the sorted output.
Example
Assuming the output of `ps -ef | grep ora` is:
oracle 1234 1 0 08:00 ? 00:00:05 ora_pmon_db1
oracle 1235 1 0 08:05 ? 00:00:02 ora_dbw0_db1
oracle 1236 1 0 08:10 ? 00:00:03 ora_lgwr_db1
Using `sort -k7` will sort the processes based on the `TIME` column (CPU time), allowing you to see which Oracle processes have been consuming the most CPU time.
Why Use the `-k` Option?
- Standardization: The `-k` option is part of the POSIX standard and is supported across different UNIX and Linux distributions.
- Clarity: It clearly specifies the sort key and is more readable.
- Flexibility: Allows for complex sorting by specifying start and end positions of the sort key.
Additional Tips
- Check Your `sort` Version: You can check the version of `sort` by running `sort --version`. This can help you determine if the deprecated syntax is supported.
- Consult the Manual: Use `man sort` to read the manual and understand the available options for your system's version of `sort`.
Conclusion
- Replace Deprecated Syntax: Update `sort +6` to `sort -k7` to ensure compatibility and correct functionality.
- Understanding Fields: Remember that in `-k` syntax, fields start counting from 1, not 0.
- Ensure Correctness: Always test your commands to make sure they produce the expected output, especially when dealing with different system versions.
By updating your command, you ensure that it works correctly on modern systems and aligns with current best practices.