Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Databases - Practical PostgreSQL
Previous Page Home Next Page

Command Line Options

Here is the complete syntax to start psql :

psql [ 
options
 ] [ 
dbname
 [ 
username
 ] ] 

The optional dbname value specifies the database to initially connect to. The optional username specifies the PostgreSQL user to connect as. If either value is unspecified, psql will default to a database and username with the same name as the operating system user starting the program.

Additionally, several run-time options can be set by command-line flags. By default, psql understands both standard UNIX short options (e.g., -c , and GNU-style long options (e.g., - -command ). The latter are not available on all systems. In the following list, the UNIX short options (which are always one letter) are shown first, followed by the equivalent long option.

-a, --echo-all

Turns on the 'echo all' option, which displays all lines as they are read by psql . This option can be useful for scripting, and is equivalent to issuing the command: \set ECHO all from within psql .

-A, --no-align

Starts psql in unaligned output formatting mode. If this is not specified, the output formatting mode will be set to aligned.

-c statement , --command statement

Instead of running psql interactively, this option executes the statement that you specify. This must be a syntactically correct SQL statement, and must be devoid of any psql -specific commands.

-d database , --dbname database

Explicitly specifies the database you wish psql to initially connect to.

-e, --echo-queries

Specifies that all queries are echoed to the screen.

-E, --echo-hidden

Displays the hidden queries generated by slash commands. You can also issue the following command from within psql to accomplish the same effect: \set ECHO_HIDDEN.

-f filename , --file filename

Specifies that rather than start in interactive mode, psql should read and execute SQL from the specified filename , and process its contents as it would if input directly. After processing the file, psql exits.

-F separator , --field-separator separator

Specifies that psql should use the specified separator character as the field (column) delimiter.

-h hostname , --host hostname

Specifies the hostname of the backend machine. This is usually not necessary when connecting to a local backend process, which uses UNIX domain sockets. However, if the postmaster initializes its domain socket file somewhere other than the default path of /tmp , specifying a hostname with a leading forward slash will cause psql to interpret the hostname value as a local directory to check for the domain socket file (e.g., -h /var/pgsql will cause psql to look for a domain socket file within /var/pgsql ).

-H, --html

Starts psql in HTML output mode.

-l, --list

Displays a list of available databases to connect to.

-o filename , --output filename

Redirects psql output to filename .

-p port , --port port

Specifies TCP/IP port (or numbered UNIX domain socket) that postmaster is currently listening on. By default, this is whatever PGPORT is set to (or the default of 5432).

-P name = value , --pset name = value

Specifies the output formatting options using the same syntax as used with the \pset command. All option names are the same as for \pset, but with this command-line option you must use an an equal sign (=) instead of a space between each formatting option name and its value.

-q, --quiet

Instructs psql to work in quiet mode. No psql -specific informative messages or informational text is displayed.

-R separator , --record-separator separator

Specifies separator as the record (row) delimiter.

-s, --single-step

Specifies that psql will run in "single-step" mode. While in single-step mode, you will be prompted to either continue or cancel upon executing a SQL statement.

-S, --single-line

Specifies that psql will run in "single-line" mode. When running in this mode, a new line acts as a semi-colon to execute a SQL statement.

-t, --tuples-only

Turns off the display of extraneous table information, such as column names and footers. To accomplish this from within psql , use the \t command.

-T table_attribute , --table-attr table_attribute

Sets an HTML attribute that you wish to be placed within the <table> output while in HTML formatting mode (e.g., width=100%). If you pass more than one table_attribute to this flag, they must all be contained within double quotes. You can use \pset from within psql to insert these attributes as well.

-U username , --username username

Connects with the specified username .

-v name = value , --variable name = value

Assigns a value to a variable name , as you would do using the \set command from within psql . When separating a value from a name, use an equal sign instead of a space.

-V, --version

Displays version information.

-W, --password

Prompts for a password before connecting to a database. This setting remains for the duration of the psql session.

-x, --expanded

Activate extended row format mode. Accomplish this from within psql by using the \x slash command.

-X, --no-psqlrc

Do not read or execute the startup file ( ~/.psqlrc ).

-?, --help

Displays brief psql command line argument help.

Warning

Unstable code was introduced into version 7.0 that causes psql to obtain a password from the user when authentication is requested by the backend process; however, this code is not reliable and will sometimes fail, which will subsequently cause the connection attempt to fail. It is advisable to use the -W ( --password ) option to force a prompt if you know that such authentication will be necessary.

Databases - Practical PostgreSQL
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire