PSQL ignores port parameter

Viewed 1589

I'm trying to connect to a database which is running on a non-default port using PSQL:

PSQL SYNOPSIS
       psql [option...] [dbname [username]]

psql -h wrds-pgdata.wharton.upenn.edu –p 9737 -W myDatabase myAccountName 
psql: warning: extra command-line argument "myDatabase" ignored
psql: warning: extra command-line argument "myAccountName" ignored
Password for user 9737:

Notice that the -p command is simply ignored. Somehow psql assumes that 9737 is the username! Let's try to be more explicit:

psql -h wrds-pgdata.wharton.upenn.edu –p 9737 -d myDatabase -U myAccountName -W
psql: warning: extra command-line argument "–p" ignored
psql: warning: extra command-line argument "9737" ignored
Password for user myAccountName:

No, that's not good either! The only way I got this to work was:

PGPORT=9737; export PGPORT
psql -h wrds-pgdata.wharton.upenn.edu -d myDatabase -U myAccountName -W

I'm using psql (PostgreSQL) 9.5.8. Any idea's why the normal command line doesn't work?

2 Answers

That specific error is odd... but the following works for me. The last argument "wrds" is the name of the database where wrds stores everything.

psql -h wrds-pgdata.wharton.upenn.edu –p 9737 -U myUserBame -W wrds

That is most odd. I've used psql in this way many times before and had it work. And your command seems fine from reading man psql. My version is also 9.5.8 but I don't have the exact set of circumstances to test.

The only thing I can suspect is that part of the domain is being interpreted as an argument;

wrds-pgdata.wharton.upenn.edu

Could you try;

psql -h "wrds-pgdata.wharton.upenn.edu" –p 9737 -d myDatabase -U myAccountName -W

Also, the manual notes that --port=9737 is an alternate for just -p. You might have more luck with that.

Related