psql.1

来自「PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开」· 1 代码 · 共 1,822 行 · 第 1/4 页

1
1,822
字号
server. If the new connection is successfully made, theprevious connection is closed. If any of \fIdbname\fR, \fIusername\fR, \fIhost\fR or \fIport\fR are omitted or specifiedas -, the value of that parameter from theprevious connection is used. If there is no previousconnection, the \fBlibpq\fR default forthe parameter's value is used.If the connection attempt failed (wrong user name, accessdenied, etc.), the previous connection will only be kept if\fBpsql\fR is in interactive mode. Whenexecuting a non-interactive script, processing willimmediately stop with an error. This distinction was chosen asa user convenience against typos on the one hand, and a safetymechanism that scripts are not accidentally acting on thewrong database on the other hand..TP\fB\\copy { \fItable\fB [ ( \fIcolumn_list\fB ) ] | ( \fIquery\fB ) }\fRPerforms a frontend (client) copy. This is an operation thatruns an SQL COPY [\fBcopy\fR(7)] command, but instead of the serverreading or writing the specified file,\fBpsql\fR reads or writes the file androutes the data between the server and the local file system.This means that file accessibility and privileges are those ofthe local user, not the server, and no SQL superuserprivileges are required.The syntax of the command is similar to that of theSQL COPY [\fBcopy\fR(7)] command. Note that, because of this,special parsing rules apply to the \fB\\copy\fRcommand. In particular, the variable substitution rules andbackslash escapes do not apply.\\copy ... from stdin | to stdoutreads/writes based on the command input and output respectively.All rows are read from the same source that issued the command,continuing until \\. is read or the streamreaches EOF. Output is sent to the same place ascommand output. To read/write from\fBpsql\fR's standard input or output, usepstdin or pstdout. This option is usefulfor populating tables in-line within a SQL script file..sp.RS.B "Tip:"This operation is not as efficient as the SQL\fBCOPY\fR command because all data must passthrough the client/server connection. For largeamounts of data the SQL command may be preferable..RE.sp.TP\fB\\copyright\fRShows the copyright and distribution terms ofPostgreSQL..TP\fB\\d [ \fIpattern\fB ]\fR.TP\fB\\d+ [ \fIpattern\fB ]\fRFor each relation (table, view, index, or sequence) matching the\fIpattern\fR, show allcolumns, their types, the tablespace (if not the default) and any specialattributes such as NOT NULL or defaults, ifany. Associated indexes, constraints, rules, and triggers arealso shown, as is the view definition if the relation is a view.(``Matching the pattern'' is defined below.)The command form \\d+ is identical, except thatmore information is displayed: any comments associated with thecolumns of the table are shown, as is the presence of OIDs in thetable..sp.RS.B "Note:"If \fB\\d\fR is used without a\fIpattern\fR argument, it isequivalent to \fB\\dtvs\fR which will show a list ofall tables, views, and sequences. This is purely a conveniencemeasure..RE.sp.TP\fB\\da [ \fIpattern\fB ]\fRLists all available aggregate functions, together with the datatypes they operate on. If \fIpattern\fRis specified, only aggregates whose names match the pattern are shown..TP\fB\\db [ \fIpattern\fB ]\fR.TP\fB\\db+ [ \fIpattern\fB ]\fRLists all available tablespaces. If \fIpattern\fRis specified, only tablespaces whose names match the pattern are shown.If + is appended to the command name, each object is listed with its associated permissions..TP\fB\\dc [ \fIpattern\fB ]\fRLists all available conversions between character-set encodings.If \fIpattern\fRis specified, only conversions whose names match the pattern arelisted..TP\fB\\dC\fRLists all available type casts..TP\fB\\dd [ \fIpattern\fB ]\fRShows the descriptions of objects matching the \fIpattern\fR, or of all visible objects ifno argument is given. But in either case, only objects that havea description are listed.(``Object'' covers aggregates, functions, operators,types, relations (tables, views, indexes, sequences, largeobjects), rules, and triggers.) For example:.sp.nf=> \fB\\dd version\fR                     Object descriptions   Schema   |  Name   |  Object  |        Description------------+---------+----------+--------------------------- pg_catalog | version | function | PostgreSQL version string(1 row).sp.fiDescriptions for objects can be created with the COMMENT [\fBcomment\fR(7)]SQL command..TP\fB\\dD [ \fIpattern\fB ]\fRLists all available domains. If \fIpattern\fRis specified, only matching domains are shown..TP\fB\\df [ \fIpattern\fB ]\fR.TP\fB\\df+ [ \fIpattern\fB ]\fRLists available functions, together with their argument andreturn types. If \fIpattern\fRis specified, only functions whose names match the pattern are shown.If the form \\df+ is used, additional information abouteach function, including language and description, is shown..sp.RS.B "Note:".PPTo look up functions taking argument or returning values of a specifictype, use your pager's search capability to scroll through the \\dfoutput..PPTo reduce clutter, \\df does not show data type I/Ofunctions. This is implemented by ignoring functions that acceptor return type \fBcstring\fR..RE.sp.TP\fB\\dg [ \fIpattern\fB ]\fRLists all database roles. If \fIpattern\fR is specified, onlythose roles whose names match the pattern are listed.(This command is now effectively the same as \\du.).TP\fB\\distvS [ \fIpattern\fB ]\fRThis is not the actual command name: the lettersi, s,t, v,S stand for index, sequence, table, view,and system table, respectively. You can specify any or all ofthese letters, in any order, to obtain a listing of all thematching objects. The letter S restrictsthe listing to system objects; without S,only non-system objects are shown. If + isappended to the command name, each object is listed with itsassociated description, if any.If \fIpattern\fR isspecified, only objects whose names match the pattern are listed..TP\fB\\dl\fRThis is an alias for \fB\\lo_list\fR, which shows alist of large objects..TP\fB\\dn [ \fIpattern\fB ]\fR.TP\fB\\dn+ [ \fIpattern\fB ]\fRLists all available schemas (namespaces). If \fIpattern\fR (a regular expression)is specified, only schemas whose names match the pattern are listed.Non-local temporary schemas are suppressed. If +is appended to the command name, each object is listed with its associatedpermissions and description, if any..TP\fB\\do [ \fIpattern\fB ]\fRLists available operators with their operand and return types.If \fIpattern\fR isspecified, only operators whose names match the pattern are listed..TP\fB\\dp [ \fIpattern\fB ]\fRProduces a list of all available tables, views and sequences with theirassociated access privileges.If \fIpattern\fR isspecified, only tables, views and sequences whose names match the pattern are listed.The GRANT [\fBgrant\fR(7)] andREVOKE [\fBrevoke\fR(7)]commands are used to set access privileges..TP\fB\\dT [ \fIpattern\fB ]\fR.TP\fB\\dT+ [ \fIpattern\fB ]\fRLists all data types or only those that match \fIpattern\fR. The command form\\dT+ shows extra information..TP\fB\\du [ \fIpattern\fB ]\fRLists all database roles, or only those that match \fIpattern\fR..TP\fB\\edit (or \\e) [ \fIfilename\fB ]\fRIf \fIfilename\fR isspecified, the file is edited; after the editor exits, itscontent is copied back to the query buffer. If no argument isgiven, the current query buffer is copied to a temporary filewhich is then edited in the same fashion.The new query buffer is then re-parsed according to the normalrules of \fBpsql\fR, where the whole bufferis treated as a single line. (Thus you cannot make scripts thisway. Use \fB\\i\fR for that.) This means also thatif the query ends with (or rather contains) a semicolon, it isimmediately executed. In other cases it will merely wait in thequery buffer..sp.RS.B "Tip:"\fBpsql\fR searches the environmentvariables \fBPSQL_EDITOR\fR, \fBEDITOR\fR, and\fBVISUAL\fR (in that order) for an editor to use. Ifall of them are unset, \fIvi\fR is used on Unixsystems, \fInotepad.exe\fR on Windows systems..RE.sp.TP\fB\\echo \fItext\fB [ ... ]\fRPrints the arguments to the standard output, separated by onespace and followed by a newline. This can be useful tointersperse information in the output of scripts. For example:.sp.nf=> \fB\\echo `date`\fRTue Oct 26 21:40:57 CEST 1999.sp.fiIf the first argument is an unquoted -n the trailingnewline is not written..sp.RS.B "Tip:"If you use the \fB\\o\fR command to redirect yourquery output you may wish to use \fB\\qecho\fRinstead of this command..RE.sp.TP\fB\\encoding [ \fIencoding\fB ]\fRSets the client character set encoding. Without an argument, this commandshows the current encoding..TP\fB\\f [ \fIstring\fB ]\fRSets the field separator for unaligned query output. The defaultis the vertical bar (|). See also\fB\\pset\fR for a generic way of setting outputoptions..TP\fB\\g [ { \fIfilename\fB | |\fIcommand\fB } ]\fRSends the current query input buffer to the server andoptionally stores the query's output in \fIfilename\fR or pipes the outputinto a separate Unix shell executing \fIcommand\fR. A bare\\g is virtually equivalent to a semicolon. A\\g with argument is a ``one-shot''alternative to the \fB\\o\fR command..TP\fB\\help (or \\h) [ \fIcommand\fB ]\fRGives syntax help on the specified SQLcommand. If \fIcommand\fRis not specified, then \fBpsql\fR will listall the commands for which syntax help is available. If\fIcommand\fR is anasterisk (*), then syntax help on allSQL commands is shown..sp.RS.B "Note:"To simplify typing, commands that consists of several words donot have to be quoted. Thus it is fine to type \fB\\helpalter table\fR..RE.sp.TP\fB\\H\fRTurns on HTML query output format. If theHTML format is already on, it is switchedback to the default aligned text format. This command is forcompatibility and convenience, but see \fB\\pset\fRabout setting other output options..TP\fB\\i \fIfilename\fB\fRReads input from the file \fIfilename\fR and executes it asthough it had been typed on the keyboard..sp.RS.B "Note:"If you want to see the lines on the screen as they are read youmust set the variable ECHO toall..RE.sp.TP\fB\\l (or \\list)\fR.TP\fB\\l+ (or \\list+)\fRList the names, owners, and character set encodings of all the databases inthe server. If + is appended to the commandname, database descriptions are also displayed..TP\fB\\lo_export \fIloid\fB \fIfilename\fB\fRReads the large object with OID \fIloid\fR from the database andwrites it to \fIfilename\fR. Note that this issubtly different from the server function\fBlo_export\fR, which acts with the permissionsof the user that the database server runs as and on the server'sfile system..sp.RS.B "Tip:"Use \fB\\lo_list\fR to find out the large object'sOID..RE.sp.TP\fB\\lo_import \fIfilename\fB [ \fIcomment\fB ]\fRStores the file into a PostgreSQLlarge object. Optionally, it associates the givencomment with the object. Example:.sp.nffoo=> \fB\\lo_import '/home/peter/pictures/photo.xcf' 'a picture of me'\fRlo_import 152801.sp.fiThe response indicates that the large object received object ID152801 which one ought to remember if one wants to access theobject ever again. For that reason it is recommended to alwaysassociate a human-readable comment with every object. Those canthen be seen with the \fB\\lo_list\fR command.Note that this command is subtly different from the server-side\fBlo_import\fR because it acts as the local useron the local file system, rather than the server's user and filesystem..TP\fB\\lo_list\fRShows a list of all PostgreSQLlarge objects currently stored in the database,along with any comments provided for them..TP\fB\\lo_unlink \fIloid\fB\fRDeletes the large object with OID\fIloid\fR from thedatabase..sp.RS.B "Tip:"Use \fB\\lo_list\fR to find out the large object'sOID..RE.sp.TP\fB\\o [ {\fIfilename\fB | |\fIcommand\fB} ]\fRSaves future query results to the file \fIfilename\fR or pipes future resultsinto a separate Unix shell to execute \fIcommand\fR. If no arguments arespecified, the query output will be reset to the standard output.``Query results'' includes all tables, commandresponses, and notices obtained from the database server, aswell as output of various backslash commands that query thedatabase (such as \fB\\d\fR), but not errormessages..sp.RS.B "Tip:"To intersperse text output in between query results, use\fB\\qecho\fR..RE.sp.TP\fB\\p\fRPrint the current query buffer to the standard output..TP\fB\\password [ \fIusername\fB ]\fRChanges the password of the specified user (by default, the currentuser). This command prompts for the new password, encrypts it, andsends it to the server as an \fBALTER ROLE\fR command. Thismakes sure that the new password does not appear in cleartext in thecommand history, the server log, or elsewhere..TP\fB\\pset \fIparameter\fB [ \fIvalue\fB ]\fRThis command sets options affecting the output of query resulttables. \fIparameter\fRdescribes which option is to be set. The semantics of\fIvalue\fR dependthereon.Adjustable printing options are:.RS.TP\fBformat\fRSets the output format to one of unaligned,aligned, html,latex, or troff-ms.Unique abbreviations are allowed. (That would mean one letteris enough.)``Unaligned'' writes all columns of a row on aline, separated by the currently active field separator. Thisis intended to create output that might be intended to be readin by other programs (tab-separated, comma-separated).``Aligned'' mode is the standard, human-readable,nicely formatted text output that is default. The``HTML'' and``LaTeX'' modes put out tables that are intended tobe included in documents using the respective mark-uplanguage. They are not complete documents! (This might not beso dramatic in HTML, but in LaTeX you musthave a complete document wrapper.).TP\fBborder\fRThe second argument must be a number. In general, the higherthe number the more borders and lines the tables will have,but this depends on the particular format. InHTML mode, this will translate directlyinto the border=... attribute, in theothers only values 0 (no border), 1 (internal dividing lines),and 2 (table frame) make sense..TP\fBexpanded (or x)\fRToggles between regular and expanded format. When expandedformat is enabled, query results are displayed in twocolumns, with the column name on the left and the data onthe right. This mode is useful if the data wouldn't fit on thescreen in the normal ``horizontal'' mode.Expanded mode is supported by all four output formats..TP\fBnull\fRThe second argument is a string that should be printedwhenever a column is null. The default is not to printanything, which can easily be mistaken for, say, an emptystring. Thus, one might choose to write \\pset null\&'(null)'..TP\fBfieldsep\fRSpecifies the field separator to be used in unaligned outputmode. That way one can create, for example, tab- orcomma-separated output, which other programs might prefer. Toset a tab as field separator, type \\pset fieldsep

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?