Checking and Changing Parameters
Use this to view or change server settings such as memory size, degree of parallelism, and connection count. In all three databases, the value currently in effect and the value stored in the file (or catalog) are separate, and each parameter differs in whether it takes effect immediately, needs a reload, or needs a restart. Check that distinction before changing anything, and record the existing value.
Oracle
Required privileges: SELECT_CATALOG_ROLE to view, ALTER SYSTEM to change. In SQL*Plus, SHOW PARAMETER sga is a quick way to look.
Current value and how it can be changed
SELECT name, display_value, isdefault, ismodified,
isses_modifiable, issys_modifiable, ispdb_modifiable
FROM v$parameter
WHERE name IN ('sga_target', 'pga_aggregate_target', 'processes', 'optimizer_mode')
ORDER BY name;
issys_modifiable:IMMEDIATE(takes effect at once),DEFERRED(from new sessions onward),FALSE(write to the spfile and restart).- If
isses_modifiable = TRUE, you can change it for the session only withALTER SESSION. - If
ispdb_modifiable(12c+) isTRUE, each PDB can have a different value.
Non-default parameters, compared with the spfile
SELECT name, display_value FROM v$parameter WHERE isdefault = 'FALSE' ORDER BY name;
-- Where the memory value differs from the spfile value (what will change after a restart)
SELECT p.name, p.display_value AS memory_value, sp.display_value AS spfile_value
FROM v$parameter p
JOIN v$spparameter sp ON sp.name = p.name AND sp.isspecified = 'TRUE'
WHERE NVL(p.display_value, '-') <> NVL(sp.display_value, '-');
In RAC, also check whether V$SPPARAMETER.sid is * (all instances) or a specific instance.
Changing (SCOPE)
-- Make a copy of the parameter file before changing
CREATE PFILE = '/home/oracle/init_20261126.ora' FROM SPFILE;
ALTER SYSTEM SET pga_aggregate_target = 4G SCOPE = BOTH; -- apply now + save to spfile
ALTER SYSTEM SET processes = 1000 SCOPE = SPFILE; -- applies after restart
ALTER SYSTEM SET optimizer_index_cost_adj = 50 SCOPE = MEMORY; -- reverts on restart
ALTER SYSTEM RESET optimizer_index_cost_adj SCOPE = SPFILE; -- remove from spfile, back to the default
SCOPE = MEMORY: now only.SPFILE: from the next startup.BOTH(the default when started with an spfile): both.- In RAC, add
SID = '*'(all) orSID = 'orcl1'(one instance). ALTER SYSTEMchanges are recorded in the alert log. The history of past values is in AWRDBA_HIST_PARAMETER, but it requires a Diagnostics Pack license.
WARNING If you put an invalid value into the spfile with
SCOPE = SPFILE(for example, ansga_targetlarger than server memory), the database will not start at the next restart. In that case, runSTARTUP PFILE='...'with the pfile you made beforehand, then restore withCREATE SPFILE FROM PFILE;.
Hidden parameters
Parameters that start with an underscore (_) appear in V$PARAMETER only if they have been changed. To see all values, query the X$ tables as SYS.
SELECT a.ksppinm AS name, b.ksppstvl AS value, b.ksppstdf AS is_default, a.ksppdesc AS description
FROM x$ksppi a
JOIN x$ksppcv b ON b.indx = a.indx
WHERE a.ksppinm LIKE '\_optimizer%' ESCAPE '\'
ORDER BY a.ksppinm;
WARNING Change hidden parameters only when Oracle Support asks you to. They are undocumented and behave differently between versions, and changing them arbitrarily makes it hard to get support. When you do change one, wrap it in double quotes, as in
ALTER SYSTEM SET "_name" = value.
PostgreSQL
Required privileges: anyone can view (some values are visible only to superusers or pg_read_all_settings). ALTER SYSTEM requires superuser, or on PostgreSQL 15+ a role granted GRANT ALTER SYSTEM ON PARAMETER ....
Current value and how it is applied (context)
SELECT name, setting, unit, context, source, sourcefile, sourceline,
boot_val, reset_val, pending_restart
FROM pg_settings
WHERE name IN ('shared_buffers', 'work_mem', 'max_connections', 'random_page_cost');
context:postmaster(restart required),sighup(applied by reloading the configuration),superuseranduser(can also be changed per session withSET),backendandsuperuser-backend(from new connections),internal(cannot be changed).settingis in units ofunit. Ifshared_buffershassetting = 16384andunit = 8kB, that is 128MB. For a human-readable value, useSHOW shared_buffers;.- If
sourceisconfiguration file,sourcefile/sourcelineshow which file and line it came from.
Non-default settings
SELECT name, current_setting(name) AS value, source
FROM pg_settings
WHERE source NOT IN ('default', 'override')
ORDER BY name;
ALTER SYSTEM and reloading
ALTER SYSTEM SET work_mem = '64MB';
ALTER SYSTEM SET shared_buffers = '8GB'; -- postmaster: applies only after a restart
SELECT pg_reload_conf();
-- Values that need a restart and are not yet applied
SELECT name, setting FROM pg_settings WHERE pending_restart;
-- Check the configuration files for syntax errors
SELECT sourcefile, sourceline, name, setting, applied, error
FROM pg_file_settings
WHERE error IS NOT NULL OR NOT applied;
ALTER SYSTEM RESET work_mem; -- remove from postgresql.auto.conf
ALTER SYSTEMwrites topostgresql.auto.conf. This file is read afterpostgresql.conf, so it takes precedence. Do not manage the same value in two places.pg_reload_conf()applies only parameters atsighuplevel or below. In the shell, it is the same aspg_ctl reload.
WARNING If an invalid
postmastervalue (for example, ashared_bufferslarger than memory) gets intopostgresql.auto.conf, the server will not start at the next restart. In that case, edit the file directly. Check for errors beforehand withpg_file_settings.
Per-database and per-role settings
ALTER DATABASE sales SET random_page_cost = 1.1;
ALTER ROLE report SET work_mem = '256MB';
ALTER ROLE report IN DATABASE sales SET statement_timeout = '5min';
-- What is set where
SELECT d.datname, r.rolname, s.setconfig
FROM pg_db_role_setting s
LEFT JOIN pg_database d ON d.oid = s.setdatabase
LEFT JOIN pg_roles r ON r.oid = s.setrole;
- They apply from the next connection. Precedence is session
SET> role+database > role > database > server settings. - To change a value only within a transaction, use
SET LOCAL work_mem = '1GB';.
SQL Server
Required privileges: anyone can view; changing with sp_configure requires ALTER SETTINGS (sysadmin, serveradmin). Database-scoped settings require ALTER ANY DATABASE SCOPED CONFIGURATION.
Server settings (sys.configurations)
SELECT name, value, value_in_use, minimum, maximum, is_dynamic, is_advanced
FROM sys.configurations
WHERE name IN ('max degree of parallelism', 'cost threshold for parallelism',
'max server memory (MB)', 'optimize for ad hoc workloads',
'backup compression default')
ORDER BY name;
-- Values that were changed but not yet applied
SELECT name, value, value_in_use, is_dynamic
FROM sys.configurations
WHERE value <> value_in_use;
valueis the stored value andvalue_in_useis the value currently in use. Ifis_dynamic = 0, it takes effect only after a restart, even afterRECONFIGURE.- Items with
is_advanced = 1are visible and changeable throughsp_configureonly whenshow advanced optionsis on.
sp_configure and RECONFIGURE
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'max degree of parallelism', 8;
EXEC sp_configure 'cost threshold for parallelism', 50;
EXEC sp_configure 'max server memory (MB)', 57344;
RECONFIGURE;
- Set MAXDOP to no more than the number of cores per NUMA node, and usually no more than 8. The SQL Server 2019+ setup wizard looks at the core count and fills in a recommended value.
- The default
cost threshold for parallelismof 5 is low for current hardware. Start at 25 to 50 and adjust while watching the number of parallel plans and theCXPACKETandCXCONSUMERwaits. - Set
max server memoryleaving a share for the OS and other processes. With the default (effectively unlimited), the OS can run short of memory. - Values outside the recommended range are applied only with
RECONFIGURE WITH OVERRIDE.
WARNING MAXDOP, cost threshold, and
max server memorytake effect immediately and flush the plan cache, so compilations can spike right after and query plans can change. Change them one at a time during quiet hours.
Database-scoped settings (SQL Server 2016+)
USE sales;
SELECT name, value, value_for_secondary, is_value_default -- is_value_default: 2017+
FROM sys.database_scoped_configurations;
ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 4;
ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = ON;
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET MAXDOP = PRIMARY;
- A database-scoped
MAXDOPthat is not 0 takes precedence over the server setting. The query hintOPTION (MAXDOP n)takes precedence over that. FOR SECONDARYsets the value to apply on Always On readable secondary replicas.
WARNING
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;clears the entire plan cache of that database. Every query recompiles right after, and CPU rises.
Related database options and trace flags
SELECT name, compatibility_level, is_read_committed_snapshot_on,
is_auto_create_stats_on, is_auto_update_stats_on, is_query_store_on
FROM sys.databases;
DBCC TRACESTATUS(-1); -- trace flags enabled globally