Questions tagged [postgresql]

PostgreSQL is an open-source, relational database management system (RDBMS) available for all major platforms including Linux, UNIX, Windows and OS X. Please mention your version of Postgres when asking questions. Questions concerning administration or advanced features are best directed to dba.stackexchange.com.

PostgreSQL (often "Postgres", never "Postgre"), is an object-relational database management system (ORDBMS) available for all major operating systems. It is free and open source software released under the PostgreSQL License, an MIT-style license. PostgreSQL is developed by the PostgreSQL Global Development Group, consisting of volunteers employed by companies such as Red Hat and EnterpriseDB.

PostgreSQL is pronounced as "post-grez-q-l". Postgres is pronounced as "post-grez".

Numerous forks of Postgres exist for specialized tasks, such as Greenplum Database, Amazon Redshift, ParAccel, Postgres-XC, Postgres-XL, PPAS, etc. Their features and syntax differ from stock PostgreSQL. Declare what you are using and add a tag.

PostgreSQL Features

How to ask good questions

For performance questions consider instructions for .

For questions targeting a specific version add a version tag: , etc.

Questions concerning administration or advanced features are best directed to dba.stackexchange.com.

The Guide to Reporting Problems on the PostgreSQL wiki is useful reading.

  • Show at least your major PostgreSQL version from SELECT version().

  • Include the full text of relevant error messages, SQL queries, etc.

  • Where appropriate supply a test case with CREATE TABLE and INSERT statements with sample data and expected results. A fiddle site like dbfiddle.uk or sqlfiddle.com is typically useful.

  • If you've asked previous, related questions, add a link.

  • If you re-post a mailing list question, link to the page in the mailing list archives. And vice versa.

  • Know about PostgreSQL current settings/backend config with:

     SELECT name, current_setting(name), source FROM pg_settings
     WHERE  source NOT IN ('default', 'override');
    

Resources

Useful links

137468 questions
2036
votes
24 answers

PostgreSQL: Show tables in PostgreSQL

What's the equivalent to show tables (from MySQL) in PostgreSQL?
flybywire
  • 232,954
  • 184
  • 384
  • 491
1939
votes
22 answers

PostgreSQL "DESCRIBE TABLE"

How do you perform the equivalent of Oracle's DESCRIBE TABLE in PostgreSQL (using the psql command)?
Mr. Muskrat
  • 20,515
  • 3
  • 18
  • 19
1874
votes
8 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
  • 20,984
  • 5
  • 23
  • 38
1556
votes
18 answers

Select first row in each GROUP BY group?

As the title suggests, I'd like to select the first row of each set of rows grouped with a GROUP BY. Specifically, if I've got a purchases table that looks like this: SELECT * FROM purchases; My Output: id | customer | total ---+----------+------ …
David Wolever
  • 130,273
  • 78
  • 311
  • 472
1246
votes
27 answers

How can I drop all the tables in a PostgreSQL database?

How can I drop all tables in PostgreSQL, working from the command line? I don't want to drop the database itself, just all tables and all the data in them.
AP257
  • 72,861
  • 84
  • 184
  • 258
1226
votes
20 answers

PostgreSQL: How to change PostgreSQL user password?

How do I change the password for PostgreSQL user?
Saad
  • 19,836
  • 13
  • 41
  • 68
1210
votes
13 answers

How to switch databases in psql?

In MySQL, I used use database_name; What's the psql equivalent?
Blankman
  • 236,778
  • 296
  • 715
  • 1,125
1107
votes
18 answers

PostgreSQL: Which version of PostgreSQL am I running?

I'm in a corporate environment (running Debian Linux) and didn't install it myself. I access the databases using Navicat or phpPgAdmin (if that helps). I also don't have shell access to the server running the database.
Highly Irregular
  • 32,530
  • 11
  • 45
  • 65
1061
votes
34 answers

How can I start PostgreSQL server on Mac OS X?

Final update: I had forgotten to run the initdb command. By running this command ps auxwww | grep postgres I see that postgres is not running > ps auxwww | grep postgres remcat 1789 0.0 0.0 2434892 480 s000 R+ 11:28PM 0:00.00…
Ramy
  • 17,760
  • 36
  • 94
  • 141
984
votes
17 answers

Save PL/pgSQL output from PostgreSQL to a CSV file

What is the easiest way to save PL/pgSQL output from a PostgreSQL database to a CSV file? I'm using PostgreSQL 8.4 with pgAdmin III and PSQL plugin where I run queries from.
Hoff
  • 34,679
  • 17
  • 65
  • 89
863
votes
23 answers

Getting error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails

I'm getting the error: FATAL: Peer authentication failed for user "postgres" when I try to make postgres work with Rails. Here's my pg_hba.conf, my database.yml, and a dump of the full trace. I changed authentication to md5 in pg_hba and tried…
orderof1
  • 8,922
  • 4
  • 15
  • 17
859
votes
43 answers

Can't find the 'libpq-fe.h header when trying to install pg gem

I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg gem. It gives me the following error: $ gem install pg Building native extensions. This could take a while... ERROR: Error installing pg: …
demonchand
  • 9,861
  • 6
  • 19
  • 25
832
votes
15 answers

PostgreSQL error: Fatal: role "username" does not exist

I'm setting up my PostgreSQL 9.1. I can't do anything with PostgreSQL: can't createdb, can't createuser; all operations return the error message Fatal: role h9uest does not exist h9uest is my account name, and I sudo apt-get install PostgreSQL 9.1…
h9uest
  • 8,890
  • 3
  • 14
  • 22
824
votes
21 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
  • 9,988
  • 8
  • 20
  • 29
785
votes
20 answers

Creating a copy of a database in PostgreSQL

What's the correct way to copy entire database (its structure and data) to a new one in pgAdmin?
egaga
  • 19,399
  • 10
  • 43
  • 58
1
2 3
99 100