Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

What i want to do is to make a drop down list of all the databases of my postgresql 9.3 server using php . if i can get just the sql script that can do the trick then i can handle the php part.

Thanks for your time.

share|improve this question

marked as duplicate by dezso, Paul White, Marian, Colin 't Hart, ypercubeᵀᴹ Jul 28 '15 at 9:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Jul 28 '15 at 6:01

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted

This information is stored in pg_database:

select datname
from pg_database;

Obviously you need to connect some database in order to be able to run the query.

share|improve this answer
    
for other users i have added some more in next answer. thanks .:) – Abhijit Gujar Jul 28 '15 at 6:10
SELECT pg_database.datname as "Database",
       pg_user.usename as "postgres" FROM pg_database, pg_user
WHERE pg_database.datdba = pg_user.usesysid
UNION
SELECT pg_database.datname as "Database",
       NULL as "postgres" FROM pg_database
WHERE pg_database.datdba NOT IN (SELECT usesysid FROM pg_user)
ORDER BY "Database"  -- database that belong to user postgres

SELECT pg_database.datname as "Database" FROM pg_database; -- all databases 

SELECT datname FROM pg_database
WHERE datistemplate = false;
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.