I'm using Fedora 17 and pgadmin3 to auto-connect to a postgresql database with one button click.

Every time I want to run an SQL statement, I have to do 4 steps, (open pgadmin3), (connect to the server), (connect to the database), (open a query window), (open a previous file) then FINALLY I can run my SQL statement. I want this all to be done with one click.

pgadmin3 appears to have features to do do all this work for you on the commandline:

el@defiant ~ $ pgadmin3 --help
Usage: pgadmin3 [-h] [-s <str>] [-S] [-Sc <str>] [-q] [-qc <str>] [-f <str>] [-cm <str>] [-ch <str>] [-cp <str>] [-c <str>] [-t]
  -h, --help                            show this help message
  -s, --server=<str>                    auto-connect to specified server
  -S, --serverstatus                    open server status window
  -Sc, --serverstatusconnect=<str>      connect server status window to database
  -q, --query                           open query tool
  -qc, --queryconnect=<str>             connect query tool to database
  -f, --file=<str>                      file to load into the query tool in -q or -qc mode
  -cm:<str>                             edit main configuration file
  -ch:<str>                             edit HBA configuration file
  -cp:<str>                             edit pgpass configuration file
  -c:<str>                              edit configuration files in cluster directory
  -t                                    dialog translation test mode

But I can't get it to work, I can either connect to the database or open the file I want. It doesn't seem to allow me to simultaneously connect to a server, connect to a specific database, open a query window, and open a previous sql file.

What are the proper commands to connect to server, database and open a query editor and load a file into it? I've tried a hundred variations, but pgadmin3 either just does not do anything and does not give an error message, or it does only part of what I told it to do with no error message.

This is the command I'm using, it does open my file, but it connects to the wrong database, and I have to manually change it. The command line option to choose the database does not work.

pgadmin3 --file=/home/el/Desktop/sqlfile_for_postgresql.sql --query --server=defiant
  • 1
    I'm not sure that understand you correctly, but if you don't want the GUI functionality, just run a script against a database, you can use psql with much less fuss. Oct 29, 2012 at 18:28

1 Answer 1


I found the answer to my problem. The pgadmin3 tool won't let you specify both a server and a database. The server itself HAS a default database and when you select it with the --server option, it won't let you pick a database. An error message would have been nice!

The 'defiant' server I made has in itself a default connection to a database, you have to set that default database, and you can't use commandline options to change it.

First, you must be disconnected from the default connection to the server you want to edit. Either make a new connection to a server or edit your existing one by right clicking your server, mine is: defiant(localhost:5432).

Then right click it, go to properties, you'll see a field called `maintenance DB', make that the connection to the database you want to be the default for this server connection. I set mine to kurz_prod. Click OK and restart.

Then the following command works. It opens pgadmin3, it gets a connection to the server and database that I specify, it opens a query window, it loads a previous file I specify into it. And immediately I can run statements against it.

This command is correct in opening an sql file with a connection to a server and database:

pgadmin3 --file=/home/el/Desktop/sqlfile_for_postgresql.sql --query --server=defiant
  • The term "server" for a saved connection is a bit misleading. We have discussed that before, but never came to a resolution to change terms. Oct 30, 2012 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.