postgresql_16:7.2.18.6 Files
PostgreSQL 16 > Reference > PostgreSQL Client Applications > psql > Files
psqlrc and ~/.psqlrc
Unless it is passed an -X option, psql attempts to read and execute commands from the system-wide startup file (psqlrc) and then the user's personal startup file (~/.psqlrc), after connecting to the database but before accepting normal commands. These files can be used to set up the client and/or the server to taste, typically with \set and SET commands.
The system-wide startup file is named psqlrc. By default it is sought in the installation's “system configuration” directory, which is most reliably identified by running pg_config --sysconfdir. Typically this directory will be ../etc/ relative to the directory containing the PostgreSQL executables. The directory to look in can be set explicitly via the PGSYSCONFDIR environment variable.
The user's personal startup file is named .psqlrc and is sought in the invoking user's home directory. On Windows the personal startup file is instead named %APPDATA%\postgresql\psqlrc.conf. In either case, this default file path can be overridden by setting the PSQLRC environment variable.
Both the system-wide startup file and the user's personal startup file can be made psql-version-specific by appending a dash and the PostgreSQL major or minor release identifier to the file name, for example ~/.psqlrc-16 or ~/.psqlrc-16.15. The most specific version-matching file will be read in preference to a non-version-specific file. These version suffixes are added after determining the file path as explained above.
.psql_history
The command-line history is stored in the file ~/.psql_history, or %APPDATA%\postgresql\psql_history on Windows.
The location of the history file can be set explicitly via the HISTFILE psql variable or the PSQL_HISTORY environment variable.