Home > Software design >  How to execute sql script for PostgreSQL database hosted on AWS?
How to execute sql script for PostgreSQL database hosted on AWS?

Time:04-15

I am trying to run an sql file for a database hosted on AWS RDS. The command I am using is the following:

psql -v user=myusername -v dbname=postgres -v passwd=mypassword -f ./explorerpg.sql

After running it I get the following result:

sql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

What am I missing? For those curious I am trying to get Hyperledger explorer to display the database contents of an AWS blockchain. The sql script is from Hyperledger explorer.

Any suggestions are greatly appreciated!

CodePudding user response:

You're missing the -h (or --host) option. The command you're running is trying to connect to a PostgreSQL server on your localhost. Additionally, you're trying too hard with the command line. You want something more like:

psql -U myusername -d postgres -h dbhostname.randomcharacters.us-west-2.rds.amazonaws.com -v passwd=mypassword -f ./explorerpg.sql

The password likely should not be done this way - a file containing the password is more common. But the key is to find the hostname of your RDS server and specify it with the -h option.

  • Related