Postgress-Config Files and Commands
Postgress-Config Files and Commands
1. POSTGRESQL.CONF
Purpose: The main configuration file for PostgreSQL, controlling server behavior and database settings.
Location: By default, located in the PostgreSQL data directory, typically specified during installation.
Contents:
General parameters for database operations, including memory management, logging, query optimization, and
replication settings.
Configurable categories include File Locations, Resource Usage, Query Tuning, Write-Ahead Logging (WAL),
Replication, Autovacuum, Client Connection Defaults, and more.
• This file is read on server startup and when the server receives a SIGHUP signal.
• If you edit the file on a running system, you have to SIGHUP the server for the changes to take effect, run
"pg_ctl reload –D path/to/data directory", or execute "SELECT pg_reload_conf()".
• Some parameters, which are marked below, require a server shutdown and restart to take effect.
• Any parameter can also be given as a command-line option to the server, e.g., "postgres -c
log_connections=on".
• Some parameters can be changed at run time with the "SET" SQL command.
Key Usage: The settings here influence the overall performance and functionality of the database. Adjustments can
be made to optimize resource usage, configure connections, manage authentication, and tune queries.
IMPORTANT CONFIGURATION:
1. File Locations:
Parameters that define the storage locations for PostgreSQL’s data, logs, and other key files.
Defines how memory, CPU, and disk resources are allocated for optimal performance.
Parameters that manage PostgreSQL’s WAL for data durability and crash recovery.
6. Query Tuning
Parameters that guide the query planner and executor to optimize performance.
9. Autovacuum
Sets default configurations for client connections, including timeouts and locales.
Purpose: Controls client authentication by defining who can connect to PostgreSQL, from which hosts, and what
authentication methods are required.
Contents:
Contains rules for host-based authentication, using parameters like type (local, host, hostssl), database, user,
address, and method.
Configures access control for both local and remote connections, specifying whether users must authenticate using
methods like password, SCRAM-SHA-256, or trust.
IMPORTANT CONFIGURATION:
1. Authentication Records
This file controls: which hosts are allowed to connect, how clients are authenticated, which PostgreSQL user names
they can use, which databases they can access.
2. Include Records
This file allows the inclusion of external files or directories holding more records
Key Usage: This file is crucial for database security, allowing administrators to control access by restricting IP
addresses and enforcing authentication methods.
Contents:
Contains mappings with columns specifying map name, system user, and PostgreSQL user.
Enables PostgreSQL users to log in as different roles without needing a matching operating system username.
IMPORTANT CONFIGURATION:
Key Usage: Useful in environments where OS user names differ from PostgreSQL roles, or where different systems
need access to the database without direct role naming requirements.
COMMANDS LIST
INFORMATIONAL COMMANDS
Command Description Example
\d[S+] Lists tables, views, and \d+
sequences. Displays all tables, views,
and sequences with extra
detail.
\d[S+] NAME Describes a specific table, view, \d+ employees
sequence, or index. Shows detailed information
about the employees table.
\da[S] [PATTERN] Lists aggregate functions. \da+
Lists all aggregates with
extra detail.
\dA[+] [PATTERN] Lists access methods. \dA
Displays available access
methods.
\dAc[+] [AMPTRN Lists operator classes. \dAc+
[TYPEPTRN]] Lists operator classes with
additional details.
\dAf[+] [AMPTRN Lists operator families. \dAf
[TYPEPTRN]] Lists all operator families.
\dAo[+] [AMPTRN Lists operators of operator \dAo
[OPFPTRN]] Shows operators in operator
families.
families.
\dAp[+] [AMPTRN Lists support functions of \dAp
[OPFPTRN]] Displays support functions
operator families.
of operator families.
\db[+] [PATTERN] Lists tablespaces. \db+
Shows tablespaces with
additional details.
\dc[S+] [PATTERN] Lists conversions. \dc
Displays conversions.
\dconfig[+] [PATTERN] Lists configuration parameters. \dconfig+
Displays configuration
parameters with details.
\dC[+] [PATTERN] Lists casts. \dC
Shows all available casts.
\dd[S] [PATTERN] Shows object descriptions not \dd
displayed elsewhere. Lists object descriptions.
\dD[S+] [PATTERN] Lists domains. \dD+
Lists domains with
additional information.
\ddp [PATTERN] Lists default privileges. \ddp
Shows default privileges.
\dE[S+] [PATTERN] Lists foreign tables. \dE
Displays foreign tables.
\des[+] [PATTERN] Lists foreign servers. \des+
Displays foreign servers
with details.
\det[+] [PATTERN] Lists foreign tables. \det
Shows foreign tables.
\deu[+] [PATTERN] Lists user mappings. \deu+
Displays user mappings with
additional details.
\dew[+] [PATTERN] Lists foreign-data wrappers. \dew
Lists foreign-data wrappers.
\df[anptw][S+] Lists functions filtered by type: \df+
[FUNCPTRN [TYPEPTRN Lists functions with detailed
...]]
aggregate, normal, procedure,
trigger, or window. descriptions.
\dF[+] [PATTERN] Lists text search configurations. \dF
Displays text search
configurations.
\dFd[+] [PATTERN] Lists text search dictionaries. \dFd
Lists available text search
dictionaries.
\dFp[+] [PATTERN] Lists text search parsers. \dFp
Displays text search parsers.
\dFt[+] [PATTERN] Lists text search templates. \dFt
Shows text search templates.
\dg[S+] [PATTERN] Lists roles. \dg
Lists all roles.
\di[S+] [PATTERN] Lists indexes. \di+
Shows all indexes with
details.
\dl[+] Lists large objects, same as \dl+
\lo_list. Displays large objects with
additional information.
\dL[S+] [PATTERN] Lists procedural languages. \dL
Shows procedural
languages.
\dm[S+] [PATTERN] Lists materialized views. \dm
Displays materialized views.
\dn[S+] [PATTERN] Lists schemas. \dn+
Shows schemas with
additional details.
\do[S+] [OPPTRN Lists operators. \do
[TYPEPTRN Displays operators.
[TYPEPTRN]]]
\dO[S+] [PATTERN] Lists collations. \dO+
Lists collations with extra
detail.
\dp[S] [PATTERN] Lists access privileges for tables, \dp
views, and sequences. Shows access privileges for
specified relations.
\dP[itn+] [PATTERN] Lists partitioned relations (tables \dP+
or indexes). Displays partitioned
relations.
\drds [ROLEPTRN Lists per-database role settings. \drds
[DBPTRN]] Shows role settings per
database.
\drg[S] [PATTERN] Lists role grants. \drg
Displays role grants.
\dRp[+] [PATTERN] Lists replication publications. \dRp
Shows replication
publications.
\dRs[+] [PATTERN] Lists replication subscriptions. \dRs+
Displays replication
subscriptions.
\ds[S+] [PATTERN] Lists sequences. \ds
Lists all sequences.
\dt[S+] [PATTERN] Lists tables. \dt+
Shows tables with additional
details.
\dT[S+] [PATTERN] Lists data types. \dT+
Displays all data types with
details.
\du[S+] [PATTERN] Lists roles. \du
Lists roles.
\dv[S+] [PATTERN] Lists views. \dv+
Shows views with additional
information.
\dx[+] [PATTERN] Lists extensions. \dx+
Displays extensions.
\dX [PATTERN] Lists extended statistics. \dX
Lists extended statistics.
\dy[+] [PATTERN] Lists event triggers. \dy+
Shows event triggers.
\l[+] [PATTERN] Lists databases. \l+
Displays databases with
additional information.
\sf[+] FUNCNAME Shows a function’s definition. \sf+ my_function
Displays the definition of
my_function with
additional details.
\sv[+] VIEWNAME Shows a view’s definition. \sv+ my_view
Displays the definition of
my_view with details.
\z[S] [PATTERN] Same as \dp; lists access \z+
privileges. Shows access privileges with
additional details.
FORMATTING COMMANDS
Command Description Example
\a Toggles between unaligned (plain \a
text) and aligned (table format) Switches between unaligned and
output mode. aligned output.
\C [STRING] Sets a title for the table output or \C "Sales Report"
unsets it if none is provided. Sets the title "Sales Report" for the
output.
\f [STRING] Sets or shows the field separator for \f ','
unaligned output. Sets comma as the field separator in
unaligned output.
\H Toggles HTML output mode on or \H
off. Switches to HTML output format.
\pset [NAME Sets table output options like border, \pset border 2
[VALUE]] Sets a thicker border around the
format, and title.
table.
`\t [on off]` Toggles visibility of row-only
output, hiding or showing column
headers.
\T [STRING] Sets HTML <table> tag attributes, \T 'class="myTable"'
such as class or style, or unsets them Adds a CSS class to the HTML table.
if none are provided.
`\x [on off auto]`
CONNECTIONS COMMANDS
Command Description Example
`\c[onnect] conninfo}` Connects to a new database or
{[DBNAME] [USER] changes connection
[HOST] [PORT] parameters. Use - to skip
parameters.
\conninfo Displays information about the \conninfo
current database connection, Shows current connection
including database name, user, details.
host, and port.
\encoding Displays or sets the client encoding \encoding UTF8
[ENCODING] Sets client encoding to UTF-8.
for character data, like UTF-8 or
LATIN1.
\password Securely prompts to change the \password user123
[USERNAME] Prompts to change the
password for the specified user.
password for "user123"
securely.
OPERATING SYSTEM COMMANDS
Command Description Example
\cd [DIR] Changes the current working \cd /home/user/documents
directory to the specified directory Changes directory to documents.
DIR.
\getenv Fetches the value of an \getenv mypath PATH
PSQLVAR Sets mypath to the system PATH.
environment variable ENVVAR and
ENVVAR
stores it in a psql variable PSQLVAR.
\setenv NAME Sets or unsets an environment \setenv GREETING Hello
[VALUE] Sets GREETING to "Hello".
variable NAME with an optional
value VALUE.
`\timing [on off]` Toggles the timing of SQL commands,
showing execution time in the output.
\! [COMMAND] Executes a shell command from \! ls -la
within psql or starts an interactive Lists files in the current directory.
shell if no command is given.
VARIABLE COMMANDS
Command Description Example
\prompt Prompts the user with the specified TEXT to \prompt 'Enter your
[TEXT] NAME name: ' USERNAME
set the internal variable NAME.
Prompts for username.
\set [NAME Sets the internal variable NAME to VALUE. If no \set DBNAME
[VALUE]] my_database
parameters are provided, it lists all variables.
Sets the DBNAME
variable.
\set
Lists all internal variables.
\unset NAME Unsets (deletes) the specified internal variable \unset DBNAME
NAME. Removes the DBNAME
variable.