Php

如何通過 php 或僅使用 sql 查詢獲取 postgresql 數據庫列表?

  • July 29, 2015

我想要做的是使用 php 製作我的 postgresql 9.3 伺服器的所有數據庫的下拉列表。如果我能得到可以解決問題的 sql 腳本,那麼我可以處理 php 部分。

謝謝你的時間。

此資訊儲存在pg_database

select datname
from pg_database;

顯然,您需要連接一些數據庫才能執行查詢。

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;

引用自:https://dba.stackexchange.com/questions/108282