PSQL(1) PostgreSQL Client Applications PSQL(1) NAME psql - PostgreSQL SYNOPSIS psql [option...] [dbname [username]] DESCRIPTION psql PostgreSQL PostgreSQL shell OPTIONS -a --echo-all ECHO all -A --no-align -ccommand --commandcommand psql command shell command psql SQL psql psql echo "\x\ select * from foo;" | psql SQL BEGIN/COMMIT psql -ddbname --dbnamedbname dbname -e --echo-queries ECHO queries -E --echo-hidden \d psqlECHO_HIDDEN -ffilename --filefilename filename psql \i filename - psql < filename -f shell -Fseparator --field-separatorseparator separator \pset fieldsep \f -hhostname --hosthostname Unix -H --html HTML\pset format html \H -l --list \list -ofilename --outputfilename filename\o -pport --portport TCP Unix PGPORT 5432 -Passignment --psetassignment \pset LaTeX -P format=latex -q --quiet psql psql -c psql QUIET -Rseparator --record-separatorseparator separator \pset recordsep -s --single-step -S --single-line Note: : SQL -t --tuples-only \t -Ttable_options --table-attrtable_options HTML table \pset -u psql -U -W -Uusername --usernameusername username -vassignment --setassignment --variableassignment \set -V --version psql -W --password psql \connect psql "hack" -x --expanded \x -X, --no-psqlrc ~/.psqlrc -? --help psql EXIT STATUS psql shell 0 1 2 ON_ERROR_STOP 3 USAGE CONNECTING TO A DATABASE psql PostgreSQL psql -d -h-p -U psql Unix Unix PGDATABASE PGHOSTPGPORT PGUSER psql ENTERING SQL COMMANDS SQL psql psql => $psql testdb Welcome to psql 7.4beta5, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit testdb=> SQL psql LISTEN [listen(7)] NOTIFY [notify(7)] META-COMMANDS psql '\' psql psql psql psql C \n (new line),\t (tab), \digits, \0digits, \0xdigits : psql ecpg pl/pgsql "backticks" ` shell SQL SQL FOO"BAR"BAZ fooBARbaz "A weird"" name" A weird" name name. \\ SQL SQL psql \a \pset \cd [directory] directory Tip: : \!pwd. \C [title ] \pset titletitle. "caption" HTML \connect (or\c) [dbname [username ] ] / dbname - username \connect psql -- psql \copytable SQL COPY SQL COPY psql SQL SQL COPY \copy Tip: : SQL COPY / Note: : stdin stdout psql stdin COPY -f stdout \o \copyright PostgreSQL \d [pattern ] pattern NOT NULL "" \d+ Note: : pattern\d \dtvs \da [pattern ] pattern \dc [pattern ] pattern \dC \dd [pattern ] pattern "" =>\dd version Object descriptions Schema | Name | Object | Description ------------+---------+----------+--------------------------- pg_catalog | version | function | PostgreSQL version string (1 row) COMMENT SQL \dD [pattern ] pattern \df [pattern ] pattern\df+ Note: : \df I/O cstring \distvS [pattern ] istvS index sequencetableviewsystem table S S + pattern \dl \lo_list \dn [pattern ] pattern \do [pattern ] pattern \dp [pattern ] pattern grant(7) revoke(7) grant(7) \dT [pattern ] pattern\dT+ \du [pattern ] pattern \edit (or\e) [filename ] filename psql ""\i Tip: : psql PSQL_EDITOREDITOR VISUAL/bin/vi \echotext [ ... ] =>\echo `date` Tue Oct 26 21:40:57 CEST 1999 -n Tip: : \o \qecho \encoding [encoding ] \f [string ] | \pset \g [ {filename | |command } ] filename Unix shell command \g \g ""\o \help (or\h) [command ] SQL command psql command "*" SQL Note: : \help alter table \H HTML HTML \pset \ifilename filename Note: : ECHO all \l (or\list) "+" \lo_exportloidfilename OID loid filename lo_export lo_export Tip: : \lo_list OID OID. \lo_importfilename [comment ] PostgreSQL foo=>\lo_import '/home/peter/pictures/photo.xcf' 'a picture of me' lo_import 152801 152801 \lo_list lo_import \lo_list PostgreSQL \lo_unlinkloid OIDloid Tip: : \lo_list OID OID. \o [ {filename | |command} ] filename Unix shell command "" \d Tip: : \qecho \p \psetparameter [value ] parameter value format unalignedalignedhtml latex "Unaligned" tab "Aligned" "HTML" "LaTeX" HTML LaTeX border HTML border=... 0 1 2 expanded (or x) "" null null \pset null '(null)' fieldsep tab tab \pset fieldsep '' '|' footer (x rows) recordsep tuples_only ( t) title [text ] tableattr (or T) [text ] HTML table cellpadding bgcolor border \pset border pager psql PAGER more psql \pset pager always "Examples " Tip: : \pset \a,\C,\H, \t,\T, \x Note: : \pset \q psql \qechotext [ ... ] \echo \o \r \s [filename ] filename filename psql GNU Note: : GNU psql \set [name [value [ ... ]]] name value \unset "Variables " psql Note: : SQL SET [set(7)] \t / \pset tuples_only \Ttable_options HTML table \pset tableattr table_options \timing SQL \w {filename ||command} filename Unix command \x \pset expanded \z [pattern ] pattern grant(7) revoke(7) grant(7) \dp"" \! [command ] Unix shell Unix command shell \? \d pattern * "" ? "" Unix shell [0-9] "" \dt foo*.bar* foo bar pattern \d *.* ADVANCED FEATURES VARIABLES psql Unix shell / psql \set testdb=>\set foo bar "foo" "bar" testdb=>\echo :foo bar Note: : \set \set :foo 'something' Perl PHP"soft links"" " \set bar :foo \set \unset psql psql AUTOCOMMIT on SQL BEGIN START TRANSACTION SQL off SQL COMMIT END BEGIN BEGIN Note: : ABORT ROLLBACK Note: : PostgreSQL SQL .psqlrc DBNAME ECHO all -a queries psql -e ECHO_HIDDEN PostgreSQL "noexec" ENCODING HISTCONTROL ignorespace ignoredups ignoreboth Note: : bash HISTSIZE 500 Note: : bash HOST IGNOREEOF psql EOF Control+D EOF 10 Note: : bash LASTOID oid INSERT lo_insert SQL ON_ERROR_STOP SQL psql psql -f psql 3 1 PORT PROMPT1 PROMPT2 PROMPT3 psql "Prompting " QUIET -q SINGLELINE -S SINGLESTEP -s USER / VERBOSITY defaultverbose terse SQL INTERPOLATION psql "" SQL : testdb=>\set foo 'my_table' testdb=>SELECT * FROM :foo; my_table SQL OID testdb=>\set content '\'' `cat my_file.txt` '\'' testdb=>INSERT INTO my_table VALUES (:content); my_file.txt sed testdb=>\set content '\'' `sed -e "s/'/\\\\\\'/g" < my_file.txt` '\'' 6 psql sed -e "s/'/\\\'/g" < my_file.txt shell shell -e s/'/\\'/g sed sed Unix SQL SQL "+" SQL ECPG PostgreSQL PROMPTING psql PROMPT1PROMPT2 PROMPT3 Prompt 1 psql Prompt 2 Prompt 3 SQL COPY % %M Unix [local] Unix [local:/dir/name] %m Unix [local] %> %n SET SESSION AUTHORIZATION %/ %~ %/ "~" tilde %# "#"">" SET SESSION AUTHORIZATION %R prompt 1 = ^onnect ! prompt 2 -* psql /* ... */ prompt 3 %x * ! ? %digits digits 0x 0 %:name: psqlname "Variables " %`command` command back- tick %% '%/%R%# ' prompts 1 2'>> ' prompt 3 Note: : tcsh COMMAND-LINE EDITING psql readline .psql_history psql Tab SQL tab .inputrc $if psql set disable-completion on $endif psql Readline ENVIRONMENT HOME .psqlrc.psql_history PAGER more less \pset PGDATABASE PGHOST PGPORT PGUSER PSQL_EDITOR EDITOR VISUAL \e SHELL \! TMPDIR /tmp FILES o psql $HOME/.psqlrc \set SET o $HOME/.psql_history NOTES o psql testdb=>\foo Field separator is "oo". o psql EXAMPLES testdb=>CREATE TABLE my_table ( testdb(> first integer not null default 0, testdb(> second text testdb->); CREATE TABLE testdb=>\d my_table Table "my_table" Attribute | Type | Modifier -----------+---------+-------------------- first | integer | not null default 0 second | text | testdb=>\set PROMPT1 '%n@%m %~%R%# ' peter@localhost testdb=> peter@localhost testdb=> SELECT * FROM my_table; first | second -------+-------- 1 | one 2 | two 3 | three 4 | four (4 rows) \pset peter@localhost testdb=>\pset border 2 Border style is 2. peter@localhost testdb=>SELECT * FROM my_table; +-------+--------+ | first | second | +-------+--------+ | 1 | one | | 2 | two | | 3 | three | | 4 | four | +-------+--------+ (4 rows) peter@localhost testdb=>\pset border 0 Border style is 0. peter@localhost testdb=>SELECT * FROM my_table; first second ----- ------ 1 one 2 two 3 three 4 four (4 rows) peter@localhost testdb=>\pset border 1 Border style is 1. peter@localhost testdb=>\pset format unaligned Output format is unaligned. peter@localhost testdb=>\pset fieldsep "," Field separator is ",". peter@localhost testdb=>\pset tuples_only Showing only tuples. peter@localhost testdb=>SELECT second, first FROM my_table; one,1 two,2 three,3 four,4 peter@localhost testdb=>\a\t\x Output format is aligned. Tuples only is off. Expanded display is on. peter@localhost testdb=>SELECT * FROM my_table; -[ RECORD 1 ]- first | 1 second | one -[ RECORD 2 ]- first | 2 second | two -[ RECORD 3 ]- first | 3 second | three -[ RECORD 4 ]- first | 4 second | four Postgresql man man https://github.com/man-pages-zh/manpages- zh Application 2003-11-02 PSQL(1)