Search code examples
postgresqlsslpg-restore

pg_restore using ssl certs


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 

Solution

  • 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.