snippetsqlMinor
How do I automatically set meta commands when starting psql?
Viewed 0 times
startingcommandsautomaticallymetapsqlhowwhenset
Problem
When I start a psql session, I would like certain meta commands to already be set.
For instance:
I was hoping to find an rc or config file but couldn't. The command line options don't seem comprehensive either.
For instance:
\x auto
\set ON_ERROR_STOP onI was hoping to find an rc or config file but couldn't. The command line options don't seem comprehensive either.
Solution
You are looking for the
Unless it is passed an
.psqlrc file. Per documentation:psqlrc and ~/.psqlrcUnless it is passed an
-X or -c 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.Context
StackExchange Database Administrators Q#65074, answer score: 5
Revisions (0)
No revisions yet.