pg_restore using ssl certs

Viewed 2660

Can somebody help me in restoring postgres db using SSL certs. I tried in below way but it didn't work

pg_restore "host=hostname user=username dbname=database_name sslcert=sslcert.crt sslkey=sslkey.key sslrootcert=sslroot.pem sslmode=verify-full" -f filename

It gives the below error

pg_restore: [archiver] could not open input file "host=hostname user=username dbname=database_name sslcert=sslcert.crt sslkey=sslkey.key sslrootcert=sslroot.pem sslmode=verify-full": No such file or directory 
3 Answers

The argument of pg_restore is not the connection string, but the file to restore. You use the -d option to specify the connection string:

pg_restore -d "host=..." filename

You can specify any parameters that way. A more elaborate example would be:

pg_restore  --format=custom -d "port=5432 host=<hostname> 
user=<username> dbname=<dbname> sslrootcert=root.crt 
sslkey=server.key sslcert=server.crt sslmode=verify-ca" ../filename.dump -v

Please refer to the docs here.

I use this in my case with digital ocean...

pg_restore --clean -d 'postgresql://USER:qfdvr2ata7opidy4@HOST:PORT/DATABASE?sslmode=require' --jobs 2 database.dump

@Laurenz Albe's answer is spot on. Here is just an expanded version of the answer to include the SSL certs.

pg_restore  --format=custom -d "port=5432 host=<hostname> 
user=<username> dbname=<dbname> sslrootcert=root.crt 
sslkey=server.key sslcert=server.crt sslmode=verify-ca" ../filename.dump -v

Please refer to the docs here.

Related