Questions tagged [psql]

Primary interactive shell for PostgreSQL. NOT a synonym for PostgreSQL.

psql is a terminal-based client to PostgreSQL, that's packaged with the software. It lets you edit queries interactively, issue them to PostgreSQL, and see the results. You can read and write to / from files and use it for scripting.

Additionally, psql provides a set of meta-commands and other shell-like features to facilitate writing scripts and automating a wide range of tasks.

Questions with this tag should probably be tagged , too.
But only questions dealing with the command-line interface should be tagged .


Questions referring to the procedural language "psql" for the Firebird database should be tagged with

3588 questions
2146
votes
24 answers

PostgreSQL "DESCRIBE TABLE"

How do you perform the equivalent of Oracle's DESCRIBE TABLE in PostgreSQL with psql command?
Mr. Muskrat
  • 22,772
  • 3
  • 20
  • 21
1960
votes
9 answers

How to exit from PostgreSQL command line utility: psql

What command or short key can I use to exit the PostgreSQL command line utility psql?
App Work
  • 21,899
  • 5
  • 25
  • 38
1471
votes
15 answers

How to switch databases in psql?

In MySQL, I used use database_name; What's the psql equivalent?
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
986
votes
23 answers

psql: FATAL: database "" does not exist

I'm using the PostgreSql app for mac (http://postgresapp.com/). I've used it in the past on other machines but it's giving me some trouble when installing on my macbook. I've installed the application and I ran: psql -h localhost It returns: psql:…
Ryan Rich
  • 11,637
  • 8
  • 22
  • 31
738
votes
17 answers

Run a PostgreSQL .sql file using command line arguments

I have some .sql files with thousands of INSERT statements in them and need to run these inserts on my PostgreSQL database in order to add them to a table. The files are that large that it is impossible to open them and copy the INSERT statements…
CSharpened
  • 11,674
  • 14
  • 52
  • 86
648
votes
12 answers

How do I specify a password to 'psql' non-interactively?

I am trying to automate database creation process with a shell script and one thing I've hit a road block with passing a password to psql. Here is a bit of code from the shell script: psql -U $DB_USER -h localhost -c"$DB_RECREATE_SQL" How do I pass…
Alex N.
  • 14,805
  • 10
  • 46
  • 54
526
votes
6 answers

List tables in a PostgreSQL schema

When I do a \dt in psql I only get a listing of tables in the current schema (public by default). How can I get a list of all tables in all schemas or a particular schema?
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
462
votes
8 answers

Alternate output format for psql showing one column per line with column name

I am using PostgreSQL 8.4 on Ubuntu. I have a table with columns c1 through cN. The columns are wide enough that selecting all columns causes a row of query results to wrap multiple times. Consequently, the output is hard to read. When the query…
user100464
  • 17,331
  • 7
  • 32
  • 40
411
votes
10 answers

psql - save results of command to a file

I'm using psql's \dt to list all tables in a database and I need to save the results. What is the syntax to export the results of a psql command to a file?
pstanton
  • 35,033
  • 24
  • 126
  • 168
396
votes
17 answers

Postgresql: Scripting psql execution with password

How can I call psql so that it doesn't prompt for a password? This is what I have: psql -Umyuser < myscript.sql However, I couldn't find the argument that passes the password, and so psql always prompts for it.
Axel Fontaine
  • 34,542
  • 16
  • 106
  • 137
394
votes
6 answers

Using psql how do I list extensions installed in a database?

How do I list all extensions that are already installed in a database or schema from psql? See also Finding a list of available extensions that PostgreSQL ships with
ARV
  • 6,287
  • 11
  • 31
  • 41
372
votes
8 answers

Correct way to install psql without full Postgres on macOS?

Official page do not mention such case. But many users need only psql without a local database (I have it on AWS). Brew do not have psql.
Vitaly Zdanevich
  • 13,032
  • 8
  • 47
  • 81
322
votes
10 answers

How to select a schema in postgres when using psql?

I have a postgres database with multiple schemas. When I connect to the database from a shell with psql and I run \dt it uses the default connection schema which is public. Is there a flag I can specify or how can I change the schema?
mehany
  • 3,747
  • 2
  • 17
  • 28
257
votes
3 answers

How to alter a column's data type in a PostgreSQL table?

Entering the following command into a PostgreSQL interactive terminal results in an error: ALTER TABLE tbl_name ALTER COLUMN col_name varchar (11); What is the correct command to alter the data type of a column?
tree em
  • 20,379
  • 30
  • 92
  • 130
252
votes
22 answers

Library not loaded: /usr/local/opt/readline/lib/libreadline.6.2.dylib

I just installed posgresql with homebrew and when I go on to type the command psql I get the following error: dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.2.dylib Referenced from: /usr/local/bin/psql Reason: image not…
hbejgel
  • 4,674
  • 2
  • 17
  • 27
1
2 3
99 100