Now I'm doing to take database(Postgres) backup using php. I'm using command pg_query('\d') to retrive tables. But is not working. Please help me.
\d
is a feature of the psql
command line tool. It is not available in queries.
From bytes.com
If you start psql with the -E option you can see the internal commands sent to the backend. This can often give you a lot of hints as to the best way to pull catalog data from a db:
jason=# \dt
********* QUERY **********
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN
'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as "Type",
u.usename as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;
**************************
This way, you can see what query is actually used when you use \d
in console client. When working from PHP, you have to use that query instead of \d
. You can also get equivalent queries for other commands in this way.
\d works in psql. If you want to do this on the web server, you can probably use:
Select tablename From pg_tables Where tableowner='theowner';
And of course, change "theowner" to the name of whomever the owner actually is.
精彩评论