• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/33

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

33 Cards in this Set

  • Front
  • Back

What is psql? What is edb-psql? What are the differences between them?

psql is a terminal-based front-end to Postgres. edb-psql is identical to psql

What file is executed every time psql/edb-psql starts? When is it not run?

$HOME/.psqlrc




Unless option -X is specified

What are the minimum command line parameters required to run psql/edb-psql?

-d, --dbname=, $PGDATABASE


-h, --host=, $PGHOST


-p, --port=, $PGPORT


-U, --username=, $PGUSER

How do you make psql/edb-psql execute the commands in a file then exit?

-f FILENAME

How do you make psql/edb-psql execute a command then exit?

-c COMMAND

How do you show the psql/edb-psql command history? How do you save it to a file?

\s - show the command history


\s FILENAME- save the command history to a file

How do you edit the psql/edb-psql query buffer then execute it?

\e

How do you edit a psql/edb-psql file then execute it?

\e FILENAME

How do you save the psql/edb-psql buffer to a file?

\w FILENAME

In psql/edb-psql how do you save all query results and output to a file?

-o filename


\o filename


\out filename

In psql/edb-psql how do you output all query results and output to a bash command?

\o | command


\out | command

In psql/edb-psql how do you reset output that has been redirected via \o to be sent to standard output instead?

\o




(no arguments)

In psql/edb-psql how do you direct the output for only the query you are executing to a file?

\g filename




Put \g instead of a ; at the end of the query. If you do not specify a filename it will function the same as ;




Think of it as a one-shot version of \o filename

In psql/edb-psql how do you direct the output for only the query you are executing to a bash command?

\g | command




Put \g instead of a ; at the end of the query. If you do not specify a filename it will function the same as ;




Think of it as a one-shot version of \o | command

In psql/edb-psql how do you declare a variable?

\set variable_name value




For example: \set city Boston

In psql/edb-psql how do you substitute a variable?

:variable_name




For example: \echo :city


Boston

In psql/edb-psql how do you delete a variable?

\unset variable_name




For example: \unset city

psql/edb-psql Special Variables

What is the psql/edb-psql variable AUTOCOMMIT? What are the possible values? What is the default?

AUTOCOMMIT on | off




The default is on.


When on, each SQL command is committed upon successful completion and 'BEGIN' or 'START' is required to delay 'COMMIT' ('END') or allow 'ROLLBACK'.


When off 'BEGIN' is implicitly issued for you and you must issue 'COMMIT' or 'END' or 'ROLLBACK' at the end

What is the psql/edb-psql variable HISTFILE? What are the possible values? What is the default?

HISTFILE filename




The default is unset or ~/.psql_history


The file name that will be used to store the history list.




Example: \set HISTFILE ~/.psql_history- :DBNAME

What is the psql/edb-psql variable ON_ERROR_ROLLBACK? What are the possible values? What is the default?

ON_ERROR_ROLLBACK on|off




Default is unset


If on it issues an implicit SAVEPOINT for you just before each command that is in a transaction block, and then rolling back to the SAVEPOINT if the command fails, the error is ignored and the transaction continues.


When unset or set to off, a statement in a transaction block that generates an error aborts the entire transaction

What is the psql/edb-psql variable ON_ERROR_STOP? What are the possible values? What is the default?

ON_ERROR_STOP




Default is unset. By default command processing continues after an error.


When this variable is set to on, processing will instead stop immediately.


In interactive mode, psql will return to the command prompt; otherwise, psql will exit, returning error code 3 to distinguish this case from fatal error conditions, which are reported using error code 1. In either case, any currently running scripts (the top-level script, if any, and any other scripts which it may have in invoked) will be terminated immediately. If the top-level command string contained multiple SQL commands, processing will stop with the current command.

What is the psql/edb-psql variable PROMPT1? What are the possible values?

PROMPT1


PROMPT2


PROMPT3


These specify what the prompts psql issues should look like. PROMPT1 is the most useful. Values are printed literally except where a percent sign (%) with character is used to substitute a value


Prompt 1 is the normal prompt that is issued when psql requests a new command.


Prompt 2 is issued when more input is expected during command input because the command was not terminated with a semicolon or a quote was not closed.


Prompt 3 is issued when you run an SQL COPY command and you are expected to type in the row values on the terminal.




Example: \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '




This feature was "shamelessly plagiarized from tcsh" :P

What is the psql/edb-psql variable VERBOSITY? What are the possible values? What is the default?

VERBOSITY tarse|default|verbose




The default is default. Controls the verbosity of error reports



What psql/edb-psql meta command lists the names, owners, and character set encodings of all the databases on the server? What else is displayed if you add +?

\l[ist][+]




\l


\list


Lists the names, owners, and character set encodings of all the databases on the server




\l+


\list+


Database sizes, default tablespaces, and descriptions are also displayed

What psql/edb-psql meta command lists the schemas? Which schemas are shown? How do you show schemas that are not displayed by default? What else is displayed if you add +?

\dn[S][+] [pattern]




\dn


Lists user-created schemas (namespaces)


\dnS


Lists all user-created AND system schemas


\dn+


Permissions and description (if any) for each schema is also listed

What psql/edb-psql meta command lists the functions? What else is displayed if you add +?

\df[+] [pattern]




\df


Lists functions




\df+


Adds owner, language, source code, and description

What psql/edb-psql meta command displays the current connection information?

\conninfo


Current connection information

What psql/edb-psql meta command quits psql/edb-psql?

\q


or


^d


Quits the edb-psqlprogram

What psql/edb-psql meta command changes the current directory?

\cd [ directory ]


Change the current working directory




Note: to print the current working directory execute '\! pwd'

How do you execute a shell terminal command in psql/edb-psql?

\! [command]


Executes specified shell terminal command (Unix or Windows CMD.EXE)

How do you escape from psql/edb-psql into a Unix or Windows CMD.EXE Shell?

\!


When \! is executed without any arguments psql/edb-psql escapes to a separate Unix or Windows CMD shell.


When you EXIT from the shell you will be returned to the psql/edb-psql terminal

How do you display the psql/edb-psql help?

\?


Shows help information about psql/edb-psql commands




\h [command]


Shows information about SQL commands or a specified SQL command




psql --help


edb-psql --help


Lists command line options for psql/edb-psql