daveg
daveg

Reputation: 1201

How can I automate running an init script when invoking a postgres DB using psql?

psql (9.6.7, server 9.5.2) on linux

I have an init script... ~/sql.ini that I always want to run after connecting to a PG DB. I can do this by typing "\i ~/sql.ini", but is there a way to do this on the command line (which I alias) ?

Upvotes: 0

Views: 917

Answers (2)

pensnarik
pensnarik

Reputation: 1252

Just put your commands in ~/.psqlrc file.

Upvotes: 1

Laurenz Albe
Laurenz Albe

Reputation: 246383

Your alias should call

PSQLRC=~/sql.ini psql

That environment variable specifies the startup file that psql executes automatically.

Upvotes: 0

Related Questions