Postgres sql list all tables in a database
"psql \dt information_schema" I am writing this command to see list of all tables and its asking ""Password for user information_schema:"" w开发者_如何学JAVAhich Password should I provide ,I meadn I m providing the postgres as password.
What you are doing with the following command:
psql \dt information_schema
is to start psql and pass the name "information_schema" as the username to connect with.
The command \dt information_schema
has to be entered after you have started psql and once you see the psql prompt.
If you want to run that directly from the command line without waiting for the psql prompt, you need to use the -c switch:
psql -c "\dt information_schema.*" postgres postgres
All parameters and the order in which they are expected are listed when you run psql --help
or have a look at the manual:
http://www.postgresql.org/docs/current/static/app-psql.html
Edit
Here is a sample console session that shows you how to do this:
c:\>psql postgres postgres Password for user postgres: psql (9.0.4) Type "help" for help. postgres=# \dt information_schema.* List of relations Schema | Name | Type | Owner --------------------+-------------------------+-------+---------- information_schema | sql_features | table | postgres information_schema | sql_implementation_info | table | postgres information_schema | sql_languages | table | postgres information_schema | sql_packages | table | postgres information_schema | sql_parts | table | postgres information_schema | sql_sizing | table | postgres information_schema | sql_sizing_profiles | table | postgres (7 rows) postgres=# \dv information_schema.* List of relations Schema | Name | Type | Owner --------------------+-----------------------------------+------+--------- information_schema | _pg_foreign_data_wrappers | view | postgres information_schema | _pg_foreign_servers | view | postgres information_schema | _pg_user_mappings | view | postgres information_schema | administrable_role_authorizations | view | postgres information_schema | applicable_roles | view | postgres information_schema | attributes | view | postgres information_schema | check_constraint_routine_usage | view | postgres information_schema | check_constraints | view | postgres information_schema | column_domain_usage | view | postgres information_schema | column_privileges | view | postgres information_schema | column_udt_usage | view | postgres information_schema | columns | view | postgres information_schema | constraint_column_usage | view | postgres information_schema | constraint_table_usage | view | postgres information_schema | data_type_privileges | view | postgres information_schema | domain_constraints | view | postgres information_schema | domain_udt_usage | view | postgres -- More --
And here is how to do it in one call:
c:\>psql -c "\dt information_schema.*" postgres postgres Password for user postgres: List of relations Schema | Name | Type | Owner --------------------+-------------------------+-------+---------- information_schema | sql_features | table | postgres information_schema | sql_implementation_info | table | postgres information_schema | sql_languages | table | postgres information_schema | sql_packages | table | postgres information_schema | sql_parts | table | postgres information_schema | sql_sizing | table | postgres information_schema | sql_sizing_profiles | table | postgres (7 rows) c:\
精彩评论