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
244
votes
20 answers

Find the host name and port using PSQL commands

I have PSQL running, and am trying to get a perl application connecting to the database. Is there a command to find the current port and host that the database is running on?
jamesatha
  • 7,280
  • 14
  • 37
  • 54
226
votes
10 answers

Create database from command line

I am trying to create a database from command line. My OS is centos and postgres version is 10.9. sudo -u postgres psql createdb test Password for user test: Why is it prompting me for the password?
Juan Reina Pascual
  • 3,988
  • 7
  • 21
  • 34
219
votes
5 answers

How to list indexes created for table in postgres

Could you tell me how to check what indexes are created for some table in postgresql ?
user6023611
188
votes
6 answers

How to show data in a table by using psql command line interface?

Is there a way to show all the content inside a table by using psql command line interface? I can use \list to show all the databases, \d to show all the tables, but how can I show all the data in a table?
Lisa
  • 2,809
  • 3
  • 24
  • 37
186
votes
13 answers

How do you use script variables in psql?

In MS SQL Server, I create my scripts to use customizable variables: DECLARE @somevariable int SELECT @somevariable = -1 INSERT INTO foo VALUES ( @somevariable ) I'll then change the value of @somevariable at runtime, depending on the value that…
Craig Walker
  • 49,871
  • 54
  • 152
  • 212
176
votes
7 answers

postgresql port confusion 5433 or 5432?

I have installed postgresql on OSX. When I run psql, I get $ psql psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5433"? However, from…
highBandWidth
  • 16,751
  • 20
  • 84
  • 131
174
votes
35 answers

PostgreSQL: Why psql can't connect to server?

I typed psql and I get this: psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? I used sudo netstat -nlp | grep…
hidemyname
  • 3,791
  • 7
  • 27
  • 41
171
votes
8 answers

PostgreSQL disable more output

I am running a script on my PostgreSQL server: psql db -f sql.sql from bash or in a cron script. It keeps trying to paginate the output with more or less. How do I disable result pagination in psql? All I want to do is change the data, I don't…
Chris
  • 1,841
  • 2
  • 12
  • 8
156
votes
17 answers

psql: command not found Mac

I installed PostgreSQL via the graphical install on http://www.postgresql.org/download/macosx/ I see it in my applications and also have the psql terminal in my applications. I need psql to work in the regular terminal for another bash script I'm…
user3147424
  • 3,022
  • 5
  • 19
  • 22
152
votes
6 answers

Psql list all tables

I would like to list all tables in the liferay database in my PostgreSQL install. How do I do that? I would like to execute SELECT * FROM applications; in the liferay database. applications is a table in my liferay db. How is this done? Here's a…
pethel
  • 5,397
  • 12
  • 55
  • 86
145
votes
5 answers

Postgresql not creating db with “createdb” as superuser, yet not outputting errors

I am working with a fresh postgresql install, with 'postgres' super user. Logged in via: sudo -u postgres psql postgres=# createdb database postgres-# \list List of databases Name | Owner | Encoding | …
Damien Roche
  • 13,189
  • 18
  • 68
  • 96
139
votes
4 answers

How can I stop a Postgres script when it encounters an error?

Is there a way to specify that when executing a sql script it stops when encountering the first error on the script, it usually continues, regardless of previous errors.
Ray
  • 1,391
  • 2
  • 8
  • 3
134
votes
2 answers

Display select results vertically in psql, as is done by MySQL's \G

In MySQL, you can terminate a select query with \G (as opposed to \g) to display the results vertically: select * from foo \G *************** id: 1 bar: Hello *************** id: 2 bar: World How can one do the same thing for PostgreSQL using…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
121
votes
6 answers

PostgreSQL: Remotely connecting to Postgres instance using psql command

I want to remotely connect to a Postgres instance. I know we can do this using the psql command passing the hostname I tried the following: psql -U postgres -p 5432 -h hostname I modified the /etc/postgresql/9.3/main/pg_hba.conf file on the target…
Hardik Kamdar
  • 2,561
  • 4
  • 16
  • 21
117
votes
14 answers

Postgres "psql not recognized as an internal or external command"

For Postgres, I keep getting this error multiple times even though I have already set the location of the bin folder to the path variable in Windows 8. Is there something else I'm missing?
as1216
  • 1,194
  • 2
  • 8
  • 11