PostgreSQL Parameters(The following are most common parameters in postgresql.conf)

A.Many Ways to set postgresql parameters

•Some parameters can be changed per session using the SETcommand.
•Some parameters can be changed at the user level using ALTER USER.
•Some parameters can be changed at the database level using ALTER DATABASE.
•The SHOW command can be used to see settings.
•The pg_settings and pg_file_settings catalog table lists settings information.

B.PostgreSQL Parameters(The following are most common parameters in postgresql.conf)

1.Connection Settings

 

 Parameter  Default Value  Description
listen_addresses localhost Specifies the addresses on which the server is to listen for connections. Use * for all.
port 5432 The port the server listens on.
max_connections 100 Maximum number of concurrent connections the server can support.
superuser_reserved_connections 3 Number of connection slots reserved for superusers.
unix_socket_directory /tmp Directory to be used for UNIX socket connections to the server
unix_socket_permissions 0777 access permissions of the Unix-domain socket.

2.Security and Authentication Settings

 

 Parameter  Default Value  Description
authentication_timeout 1 minute Maximum time to complete client authentication, in seconds.
ssl off Enables SSL connections.
ssl_ca_file Specifies the name of the file containing the SSL server certificate authority (CA).
ssl_cert_file Specifies the name of the file containing the SSL server certificate.
ssl_key_file Specifies the name of the file containing the SSL server private key.
ssl_ciphers List of SSL ciphers that may be used for secure connections.

3.Memory Settings

 

 Parameter  Default Value  Description
shared_buffers 128 MB Size of PostgreSQL shared buffer pool for a cluster.
temp_buffers 8 MB Amount of memory used by each backend for caching temporary table data.
work_mem 4 MB Amount of memory used for each sort or hash operation before switching to temporary disk files.
maintenance_work_mem 64 MB Amount of memory used for each index build or VACUUM.
temp_file_limit 1 amount of disk space that a session can use for temporary files. A transaction attempting to exceed this limit will be cancelled. Default is unlimited.

4.Query Planner Settings

 

 Parameter  Default Value  Description
random_page_cost 4.0 Estimated cost of a random page fetch, in abstract cost units. May need to be reduced to account for caching effects.
seq_page_cost 1.0 Estimated cost of a sequential page fetch, in abstract cost units. May need to be reduced to account for caching effects. Must always set random_page_cost >= seq_page_cost
effective_cache_size 4 GB Used to estimate the cost of an index scan. Rule of thumb is 75% of system memory.

5.Write Ahead Log Settings

 

 Parameter  Default value  Description
wal_level minimum Determines how much information is written to the WAL. Change this to enable replication. Other values are archive, logical and hot_standby.
fsync on Turn this off to make your database much faster –and silently cause arbitrary corruption in case of a system crash.
wal_buffer -1, autotune) The amount of memory used in shared memory for WAL data. The default setting of -1 selects a size equal to 1/32nd (about 3%) of shared_buffers.
min_wal_size 80 MB The WAL size to start recycling the WAL files.
max_wal_size 1 GB The WAL size to start checkpoint.Controls the number of WAL Segments(16MB each) after which checkpoint is forced.
checkpoint_timeout 5 minutes Maximum time between checkpoints.
wal_compression off The WAL of Full Page write will be compressed and written.

6.Where To Log

log_destination-Valid values are combinations of stderr, csvlog, syslog, and eventlog, depending on platform.
logging_collector-Enables advanced logging features. csvlogrequires logging_collector.
‒log_directory-Directory where log files are written. Requires logging_collector.
‒log_filename-Format of log file name (e.g. postgresql-%Y-%M-%d.log). Allows regular log rotation. Requires logging_collector.
‒log_file_mode(default 0600) -On Unix systems this parameter sets the permissions for log files when logging_collectoris enabled.
‒log_rotation_age-Automatically rotate logs after this much time. Requires logging_collector.
‒log_rotation_size-Automatically rotate logs when they get this big. Requires logging_collector.

7.When To Log

 

Parameter Default value Description
client_min_messages NOTICE Messages of this severity level or above are sent to the client
log_min_messages WARNING Messages of this severity level or above are sent to the server.
log_min_error_statement ERROR When a message of this severity or higher is written to the server log, the statement that caused it is logged along with it.
log_min_duration_statement default -1, disabled When a statement runs for at least this long, it is written to the server log, with its duration.

8.What to log

 

Parameter Default value Description
log_connections off Log successful connections to the server log.
log_disconnections off Log some information each time a session disconnects, including the duration of the session.
log_error_verbosity default Can also select “terse” or “verbose”.
log_duration off Log duration of each statement.
log_line_prefix Additional details to log with each line.
log_statement none Legal values are none, ddl, mod (DDL and all other data-modifying statements), or all.
log_temp_files -1 Log temporary files of this size or larger, in kilobytes.
log_checkpoints off Causes checkpoints and restartpoints to be logged in the server log.

9.Background Writer Settings

 

Parameter Default value Description
bgwriter_delay 200 ms Specifies time between activity rounds for the background writer.
bgwriter_lru_maxpages 100 Maximum number of pages that the background writer may clean per activity round.
bgwriter_lru_multiplier 2.0 Multiplier on buffers scanned per round. By default, if system thinks 10 pages will be needed, it cleans 10 * bgwriter_lru_multiplierof 2.0 = 20.

10.Statement Behavior

 

Parameter Default value Description
search_path This parameter specifies the order in which schemas are searched. The default value for this parameter is”$user”, public.
default_tablespace Name of the tablespace in which to objects are created by default.
temp_tablespaces Tablespaces name(s) in which temporary objects are created.
statement_timeout Postgres will abort any statement that takes over the specified number of milliseconds A value of zero (the default) turns this off.

11.Vacuum Cost Settings

 

Parameter Default value Description
vacuum_cost_delay 0 ms The length of time, in milliseconds, that the process will wait when the cost limit is exceeded.
vacuum_cost_page_hit 1 The estimated cost of vacuuming a buffer found in the PostgreSQL buffer pool.
vacuum_cost_page_miss 10 The estimated cost of vacuuming a buffer that must be read into the buffer pool.
vacuum_cost_page_dirty 20 The estimated cost charged when vacuum modifies a buffer that was previously clean.
vacuum_cost_limit 200 The accumulated cost that will cause the vacuuming process to sleep.

12.Autovacuum Settings

 

Parameter Default value Description
autovacuum on Controls whether the autovacuum launcher runs, and starts worker processes to vacuum and analyze tables.
log_autovacuum_min_duration -1 Autovacuum tasks running longer than this duration are logged. Can now be specified per table.
autovacuum_max_workers 3 Maximum number of autovacuum worker processes which may be running at one time.
autovacuum_work_mem default -1, to use maintenance_work_mem Maximum amount of memory used by each autovacuum worker.

 

PostgreSQL DBA part 3 :-How to start/stop postgresql database

A.Stopping postgresql database

pg_ctl can be used to stop a database cluster

•pg_ctl supports three modes of shutdown
−smart quit after all clients have disconnected
−fast (default)quit directly, with proper shutdown
−immediate quit without complete shutdown; will lead to recovery

•Syntax
−pg_ctl stop [-W] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]

-bash-4.1$ pwd
/opt/edb/as9.6/bin
-bash-4.1$ ./pg_ctl -D /opt/edb/as9.6/data -mf stop
waiting for server to shut down.... done
server stopped
-bash-4.1$ ps -ef|grep postgresql
54322 12838 12225 0 09:30 pts/2 00:00:00 grep postgresql

B.Starting postgresql database

pg_ctl can be used to start a database cluster

Choose a unique port for postmaster
•Change the port in postgresql.conf

•pg_ctl utility can be used to start a cluster
•Syntax
−pg_ctl start [options]
−Options
-D location of the database storage area
-l write (or append) server log to FILENAME
-w wait until operation completes
-t seconds to wait when using -w option

-bash-4.1$ ./pg_ctl -D /opt/edb/as9.6/data -mf start
server starting
-bash-4.1$ 2018-05-08 09:30:19 IST LOG: redirecting log output to logging collector process
2018-05-08 09:30:19 IST HINT: Future log output will appear in directory "pg_log".
-bash-4.1$ ps -ef|grep post
root 1947 1 0 May07 ? 00:00:00 /usr/libexec/postfix/master
postfix 1956 1947 0 May07 ? 00:00:00 qmgr -l -t fifo -u
postfix 12663 1947 0 09:13 ? 00:00:00 pickup -l -t fifo -u
54322 12841 1 0 09:30 pts/2 00:00:00 /opt/edb/as9.6/bin/edb-postgres -D /opt/edb/as9.6/data
54322 12842 12841 0 09:30 ? 00:00:00 postgres: logger process
54322 12844 12841 0 09:30 ? 00:00:00 postgres: checkpointer process
54322 12845 12841 0 09:30 ? 00:00:00 postgres: writer process
54322 12846 12841 0 09:30 ? 00:00:00 postgres: wal writer process
54322 12847 12841 0 09:30 ? 00:00:00 postgres: autovacuum launcher process
54322 12848 12841 0 09:30 ? 00:00:00 postgres: stats collector process
54322 12849 12841 0 09:30 ? 00:00:00 postgres: bgworker: dbms_aq launcher

C.pg_controldatacan be used to view the control information for a database cluster

-bash-4.1$ ./pg_controldata /opt/edb/as9.6/data
pg_control version number: 960
Catalog version number: 201608131
Database system identifier: 6551197085840965172
Database cluster state: in production
pg_control last modified: Tue 08 May 2018 09:30:19 AM IST
Latest checkpoint location: 0/274D828
Prior checkpoint location: 0/274D7B8
Latest checkpoint's REDO location: 0/274D828
Latest checkpoint's REDO WAL file: 000000010000000000000002
Latest checkpoint's TimeLineID: 1
Latest checkpoint's PrevTimeLineID: 1
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID: 0:2347
Latest checkpoint's NextOID: 24581
Latest checkpoint's NextMultiXactId: 1
Latest checkpoint's NextMultiOffset: 0
Latest checkpoint's oldestXID: 2326
Latest checkpoint's oldestXID's DB: 1
Latest checkpoint's oldestActiveXID: 0
Latest checkpoint's oldestMultiXid: 1
Latest checkpoint's oldestMulti's DB: 1
Latest checkpoint's oldestCommitTsXid:0
Latest checkpoint's newestCommitTsXid:0
Time of latest checkpoint: Tue 08 May 2018 09:29:55 AM IST
Fake LSN counter for unlogged rels: 0/1
Minimum recovery ending location: 0/0
Min recovery ending loc's timeline: 0
Backup start location: 0/0
Backup end location: 0/0
End-of-backup record required: no
wal_level setting: minimal
wal_log_hints setting: off
max_connections setting: 100
max_worker_processes setting: 8
max_prepared_xacts setting: 0
max_locks_per_xact setting: 64
track_commit_timestamp setting: off
Maximum data alignment: 8
Database block size: 8192
Blocks per segment of large relation: 131072
WAL block size: 8192
Bytes per WAL segment: 16777216
Maximum length of identifiers: 64
Maximum columns in an index: 32
Maximum size of a TOAST chunk: 1996
Size of a large-object chunk: 2048
Date/time type storage: 64-bit integers
Float4 argument passing: by value
Float8 argument passing: by value
Data page checksum version: 0