Questions tagged [postgresql]

All versions of PostgreSQL. Add an additional version-specific tag like [postgresql-13] if that context is relevant.

PostgreSQL is a powerful, open source ACID compliant MVCC database system with a proven architecture that has earned a strong reputation for standards-compliance, reliability, data integrity, and extensibility.

PostgreSQL runs on all major operating systems and supports most of the major features of SQL:2016 including foreign keys, transactions, and window functions, views and materialized views, triggers, and CTEs (including recursive CTEs).
Functions and procedures can be written in multiple languages including C, PL/pgSQL, Python, Perl, TCL, and numerous other languages including Java, Lua, R, sh, and v8 ECMAScript/JavaScript.

Types

PostgreSQL supports most of the standard SQL types including:

Indexes

PostgreSQL supports multicolumn, unique, full, partial and functional indexes, and combinations thereof. Index types include B-tree, Hash, GiST, SP-GiST, GIN and BRIN.

Replication and High Availability

PostgreSQL supports both logical replication, and WAL-shipping.

Extensions

A multitude of extensions provides additional capabilities. Notably, the spatial extension PostGIS is the best in the industry. See also

License

PostgreSQL is released under the PostgreSQL License, a liberal Open Source license, similar to the BSD or MIT licenses.

15937 questions
1500
votes
8 answers

How do I list all databases and tables using psql?

I am trying to learn PostgreSQL administration and have started learning how to use the psql command line tool. When I log in with psql --username=postgres, how do I list all databases and tables? I have tried \d, d and dS+ but nothing is listed. I…
Jonas
  • 31,495
  • 27
  • 59
  • 64
487
votes
5 answers

List all columns for a specified table

I'm looking for a precise piece of information in a database which I have no knowledge about. The database is on a separate machine, but I can log into it, and launch a psql command line, with administrator rights. It's a third-party product, and…
Stephane Rolland
  • 7,903
  • 8
  • 29
  • 40
384
votes
4 answers

How do I list all schemas in PostgreSQL?

When using PostgreSQL v9.1, how do I list all of the schemas using SQL? I was expecting something along the lines of: SELECT something FROM pg_blah;
Stéphane
  • 4,945
  • 4
  • 17
  • 12
359
votes
4 answers

How to insert values into a table from a select query in PostgreSQL?

I have a table items (item_id serial, name varchar(10), item_group int) and a table items_ver (id serial, item_id int, name varchar(10), item_group int). Now I want to insert a row into items_ver from items. Is there any short SQL-syntax for doing…
Jonas
  • 31,495
  • 27
  • 59
  • 64
332
votes
3 answers

How can I time SQL-queries using psql?

I would like to benchmark some SQL-queries agains my PostgreSQL database. Is there any way I can time SQL-queries using psql?
Jonas
  • 31,495
  • 27
  • 59
  • 64
330
votes
12 answers

connect to PostgreSQL server: FATAL: no pg_hba.conf entry for host

I am trying to run a website sent to me but after doing so this error appeared connect to PostgreSQL server: FATAL: no pg_hba.conf entry for host "4X.XXX.XX.XXX", user "userXXX", database "dbXXX", SSL off in C:\xampp\htdocs\xmastool\index.php on…
Jin
  • 3,413
  • 3
  • 12
  • 6
279
votes
10 answers

List the database privileges using psql

I'm in the middle of a database server migration and I can't figure (after googling and searching here) how can I list the database privileges (or all the privileges across the server) on PostgreSQL using the psql command line tool? I'm on Ubuntu…
pedrosanta
  • 3,093
  • 3
  • 15
  • 7
218
votes
6 answers

Force drop db while others may be connected

I need to remove a database from a PostgreSQL DB cluster. How can I do it even if there are active connections? I need sort of a -force flag, that will drop all connections and then the DB. How can I implement it? I'm using dropdb currently, but…
Alex
  • 2,375
  • 2
  • 16
  • 7
212
votes
3 answers

Granting a user account permission to create databases in PostgreSQL

How do I give a user account in PostgreSQL the ability to create and drop databases? Is there a way to do this with GRANT?
GSto
  • 2,223
  • 2
  • 13
  • 6
201
votes
5 answers

Granting access to all tables for a user

I'm new to Postgres and trying to migrate our MySQL databases over. In MySQL I can grant SELECT, UPDATE, INSERT, and DELETE privileges on a low privileged user and enable those grants to apply to all tables in a specified database. I must be…
PlaidFan
  • 2,115
  • 2
  • 13
  • 7
193
votes
17 answers

How do I find PostgreSQL's data directory?

I forgot how I started PostgreSQL the last time (it was months ago) and I don't remember where the data directory is located. The postgres command seems to require the location of the data directory. I'm on MacOsX if that helps. /usr/local/postgres…
randomguy
  • 2,081
  • 2
  • 13
  • 6
184
votes
5 answers

How to get the name of the current database from within PostgreSQL?

Using \c in PostgreSQL will connect to the named database. How can the name of the current database be determined? Entering: my_db> current_database(); produces: ERROR: syntax error at or near "current_database" LINE 1:…
Amelio Vazquez-Reina
  • 1,967
  • 2
  • 13
  • 8
177
votes
12 answers

SQL: SELECT All columns except some

Is there a way to SELECT all columns in a table, except specific ones? IT would be very convenient for selecting all the non-blob or non-geometric columns from a table. Something like: SELECT * -the_geom FROM segments; I once heard that this…
Adam Matan
  • 11,019
  • 29
  • 79
  • 94
145
votes
3 answers

PostgreSQL multi-column unique constraint and NULL values

I have a table like the following: create table my_table ( id int8 not null, id_A int8 not null, id_B int8 not null, id_C int8 null, constraint pk_my_table primary key (id), constraint u_constrainte unique (id_A, id_B,…
Manuel Leduc
  • 1,561
  • 2
  • 10
  • 5
143
votes
4 answers

Optimizing queries on a range of timestamps (two columns)

I use PostgreSQL 9.1 on Ubuntu 12.04. I need to select records inside a range of time: my table time_limits has two timestamp fields and one integer property. There are additional columns in my actual table that are not involved with this…
Stephane Rolland
  • 7,903
  • 8
  • 29
  • 40
1
2 3
99 100