postgres data directory empty but table exits - postgresql

I'm confused on where to find locations of a database in PostgreSQL.
I know the command SHOW data_directory. Specifically, I set up a cluster in the location data/postgres. When I connect to this cluster and create database in it, SHOW data_directory returns the following result:
yql#ubuntu1804:/data/postgresdb$ sudo -u postgres psql -p 5433
Password:
psql (10.6 (Ubuntu 10.6-0ubuntu0.18.04.1))
Type "help" for help.
postgres=# \c sample
You are now connected to database "sample" as user "postgres".
sample=# show data_directory;
data_directory
----------------
/postgresdb
(1 row)
Using \dt lists the following results, so the database should not be empty:
List of relations
Schema | Name | Type | Owner
--------+--------------------------+-------+----------
citydb | address | table | postgres
citydb | address_to_bridge | table | postgres
citydb | address_to_building | table | postgres
citydb | ade | table | postgres
citydb | aggregation_info | table | postgres
citydb | appear_to_surface_data | table | postgres
citydb | appearance | table | postgres
citydb | breakline_relief | table | postgres
citydb | bridge | table | postgres
citydb | bridge_constr_element | table | postgres
citydb | bridge_furniture | table | postgres
citydb | bridge_installation | table | postgres
citydb | bridge_open_to_them_srf | table | postgres
citydb | bridge_opening | table | postgres
citydb | bridge_room | table | postgres
citydb | bridge_thematic_surface | table | postgres
citydb | building | table | postgres
citydb | building_furniture | table | postgres
citydb | building_installation | table | postgres
citydb | city_furniture | table | postgres
citydb | citymodel | table | postgres
citydb | cityobject | table | postgres
citydb | cityobject_genericattrib | table | postgres
citydb | cityobject_member | table | postgres
citydb | cityobjectgroup | table | postgres
citydb | database_srs | table | postgres
citydb | external_reference | table | postgres
citydb | generalization | table | postgres
citydb | generic_cityobject | table | postgres
citydb | grid_coverage | table | postgres
citydb | group_to_cityobject | table | postgres
citydb | implicit_geometry | table | postgres
citydb | index_table | table | postgres
citydb | land_use | table | postgres
citydb | masspoint_relief | table | postgres
citydb | objectclass | table | postgres
citydb | opening | table | postgres
However, the directory /data/postgresdb is empty. How could this be the case? If so, where are all these tables stored?
Thanks!

Related

Why does selecting all tables from postgres gives different results based on syntax used

If I log into postgres and switch to the postgres database, when I check for tables with this command I get nothing back:
postgres=# \c postgres
You are now connected to database "postgres" as user "postgres".
postgres=# \dt+
Did not find any relations.
However if I do a select on the DB tables I do see that the tables are there:
postgres=# SELECT *
postgres-# FROM pg_catalog.pg_tables
postgres-# WHERE schemaname != 'pg_catalog' AND
postgres-# schemaname != 'information_schema';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
------------+----------------+------------+------------+------------+----------+-------------+-------------
pgagent | pga_jobclass | postgres | | t | f | t | f
pgagent | pga_job | postgres | | t | f | t | f
pgagent | pga_jobagent | postgres | | t | f | t | f
pgagent | pga_jobstep | postgres | | t | f | t | f
pgagent | pga_schedule | postgres | | t | f | t | f
pgagent | pga_exception | postgres | | t | f | t | f
pgagent | pga_joblog | postgres | | t | f | t | f
pgagent | pga_jobsteplog | postgres | | t | f | t | f
(8 rows)
Why do I get nothing when I use \dt+ but I can see the tables using a select statement?
I think that this will help LINK
\d [NAME] describe table, index, sequence, or view
\d{t|i|s|v|S} [PATTERN] ("+" detail) list tables/indexes/sequences/views/system tables
\da [PATTERN] list aggregate functions
\db [PATTERN] list tablespaces (add "+" for more detail)
use \dt+ *
the * to match all as the command needs a pattern
The reason is that the pgagent schema is not on your search_path. \dt will only show those tables that you can access without schema qualification.

After running CREATE TABLE with psql, the table cannot be found [duplicate]

This question already has answers here:
In psql, why do some commands have no effect?
(2 answers)
Closed 2 years ago.
I have been trying to create a table in PostgreSQL but have been getting the following error when I try to list tables with \dt - Did not find any relations.
I used the following create statement - create table jobs( id serial primary key, title text, link text, company text) inside a database named scrape
If I use \dt *.* then a list of tables appear which seem to built-ins -
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
pg_catalog | pg_aggregate | table | postgres
pg_catalog | pg_am | table | postgres
pg_catalog | pg_amop | table | postgres
pg_catalog | pg_amproc | table | postgres
pg_catalog | pg_attrdef | table | postgres
pg_catalog | pg_attribute | table | postgres
pg_catalog | pg_auth_members | table | postgres
pg_catalog | pg_authid | table | postgres
pg_catalog | pg_cast | table | postgres
pg_catalog | pg_class | table | postgres
pg_catalog | pg_collation | table | postgres
pg_catalog | pg_constraint | table | postgres
pg_catalog | pg_conversion | table | postgres
pg_catalog | pg_database | table | postgres
pg_catalog | pg_db_role_setting | table | postgres
pg_catalog | pg_default_acl | table | postgres
pg_catalog | pg_depend | table | postgres
pg_catalog | pg_description | table | postgres
pg_catalog | pg_enum | table | postgres
pg_catalog | pg_event_trigger | table | postgres
pg_catalog | pg_extension | table | postgres
pg_catalog | pg_foreign_data_wrapper | table | postgres
pg_catalog | pg_foreign_server | table | postgres
pg_catalog | pg_foreign_table | table | postgres
pg_catalog | pg_index | table | postgres
pg_catalog | pg_inherits | table | postgres
pg_catalog | pg_init_privs | table | postgres
pg_catalog | pg_language | table | postgres
pg_catalog | pg_largeobject | table | postgres
pg_catalog | pg_largeobject_metadata | table | postgres
pg_catalog | pg_namespace | table | postgres
pg_catalog | pg_opclass | table | postgres
pg_catalog | pg_operator | table | postgres
pg_catalog | pg_opfamily | table | postgres
pg_catalog | pg_partitioned_table | table | postgres
pg_catalog | pg_pltemplate | table | postgres
pg_catalog | pg_policy | table | postgres
pg_catalog | pg_proc | table | postgres
pg_catalog | pg_publication | table | postgres
pg_catalog | pg_publication_rel | table | postgres
pg_catalog | pg_range | table | postgres
pg_catalog | pg_replication_origin | table | postgres
pg_catalog | pg_rewrite | table | postgres
pg_catalog | pg_seclabel | table | postgres
pg_catalog | pg_sequence | table | postgres
pg_catalog | pg_shdepend | table | postgres
pg_catalog | pg_shdescription | table | postgres
pg_catalog | pg_shseclabel | table | postgres
pg_catalog | pg_statistic | table | postgres
pg_catalog | pg_statistic_ext | table | postgres
pg_catalog | pg_statistic_ext_data | table | postgres
pg_catalog | pg_subscription | table | postgres
pg_catalog | pg_subscription_rel | table | postgres
pg_catalog | pg_tablespace | table | postgres
pg_catalog | pg_transform | table | postgres
pg_catalog | pg_trigger | table | postgres
pg_catalog | pg_ts_config | table | postgres
pg_catalog | pg_ts_config_map | table | postgres
pg_catalog | pg_ts_dict | table | postgres
pg_catalog | pg_ts_parser | table | postgres
pg_catalog | pg_ts_template | table | postgres
pg_catalog | pg_type | table | postgres
pg_catalog | pg_user_mapping | table | postgres
I also checked the schemas whether they were public or not -
List of schemas
Name | Owner | Access privileges | Description
--------+----------+----------------------+------------------------
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
(1 row)
If it helps I am also including the users here -
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
arif | Superuser, Create role, Create DB | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
I also checked the databases -
scrape-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
arif | arif | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
scrape | arif | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
You got confused by the semicolons in psql. This happens to everybody in the beginning.
A statement is sent to the server only when psql has received the semicolon that terminates the statement. Otherwise, all you get is a slightly changed prompt that indicates that psql is waiting for a continuation line.
So if you enter
CREATE TABLE mytab (x integer)
without a semicolon, nothing much happens yet.
Then you realize that you forgot the terminating semicolon, and you enter
CREATE TABLE mytab (x integer);
Now psql will consider both lines a single statement and send it to the server, which results in the error message you see.
When in doubt, you can always press Ctrl+C to clear the state and discard the statement buffer.

Two database with the same name - how to dump?

I have two database with the same name after a manipulation error (I think).
When I try to dump the one owned by bussiere it always dumps the empty one owned by postgres.
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+-------+-----------------------
dbbiotech | bussiere | SQL_ASCII | C | C |
ddbiotech | postgres | SQL_ASCII | C | C | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | bussiere=CTc/postgres
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
You don't. The name is different: dbbiotech is not ddbiotech.
Looks like a misunderstanding. It wouldn't be possible to have the same name twice in the same DB cluster to begin with. Postgres does not allow it.

PostgreSQL - No relations found.

I’m totally new to developer world, so I apologize if I’m not make my question clearly, please don’t be hesitate to point out if I did any wrong. Thanks.
I faced this problem on setting my PostgreSQL DB, no relations found when type command timlin=# \d.
I did try below solution to fix but it didn’t work.
postgresql database owner can't access database - "No relations found."
Below is my situation
timlin=# \dn+
List of schemas
Name | Owner | Access privileges | Description
--------+--------+-------------------+————————————
public | timlin | timlin=UC/timlin +| standard public schema
| | =UC/timlin |
(1 row)
timlin=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------------+--------+----------+-------------+-------------+--------------------
postgres | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
psqlapp | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
psqlapp_development | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
psqlapp_test | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
psqlappdemo | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/timlin +
| | | | | timlin=CTc/timlin +
| | | | | psqlapp=CTc/timlin
template0 | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/timlin +
| | | | | timlin=CTc/timlin
template1 | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/timlin +
| | | | | timlin=CTc/timlin
timlin | timlin | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(8 rows)
timlin=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
psqlapp | | {}
timlin | Superuser, Create role, Create DB, Replication | {}
I check each one and couldn't find any difference between previous soultion.
While I try
timlin=# \d
I still got the result :
No relations found.
What do I missed ? How can I fix it ?
Please advice and thank you all in advence.
This would imply that the database timlin does not contain any tables in the public schema (which is what \d would normally list).
It sounds like you created an empty database, e.g.:
createdb -h localhost -U postgres timlin
In which case, immediately after creation, \d would return:
No relations found.
You would need to explicitly create one or more tables in order to see anything listed in the output of \d.
e.g. if you do the following:
create table foo (id serial, val text);
And then do a \d, the following output will result:
List of relations
Schema | Name | Type | Owner
--------+------------+----------+----------
public | foo | table | postgres
public | foo_id_seq | sequence | postgres
(2 rows)

Can see tables in phpPgAdmin but not in psql (or any other method)

I have recently installed postgres on my Mac and loaded a dump from our public website that I am trying to replicate locally. The pg_restore appeared to be successful, and I can see all my tables and user permissions in phpPgAdmin. They all look normal, and I can browse the data. However, when I access the database via psql I get no relations found. Similarly I have python scripts that access this database, and they also fail to find any tables.
I'm at a loss as to what to do.
Here are some psql commands I've done:
> psql -U mgd_dbo pub_mgd
psql (9.3.4)
Type "help" for help.
pub_mgd=# \d
No relations found.
pub_mgd=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+------------+----------+------------------+-------+-------------------------
postgres | postgres | UTF8 | C | C | =CTc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | mgd_dbo=CTc/postgres +
| | | | | mgd_public=CTc/postgres
pub_fe | postgres | LATIN9 | en_US.ISO8859-15 | C | =CTc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | mgd_dbo=CTc/postgres +
| | | | | mgd_public=CTc/postgres
pub_mgd | postgres | LATIN9 | en_US.ISO8859-15 | C | =CTc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | mgd_dbo=CTc/postgres +
| | | | | mgd_public=CTc/postgres
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
pub_mgd=# \dn+
List of schemas
Name | Owner | Access privileges | Description
--------+----------+----------------------+------------------------
mgd | mgd_dbo | mgd_dbo=UC/mgd_dbo +|
| | mgd_public=U/mgd_dbo |
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
(2 rows)
pub_mgd is the database I've loaded. mgd_public and mgd_dbo are the two different users our scripts use (mgd_public is a read-only user).
I've tried both users, and even as the postgres user. Yet, the results are the same, no relations.
I even tried to see if phpPgAdmin was somehow hitting a different postgres sever, so I added a new database through it, and verified that the new database appears when I do \l in psql.
Any suggestions as to what to check next?
Ask for the list of relations in the mgd schema
\d mgd.*
To make the mgd schema the default place it at the beginning of the search path
set search_path to mgd, "$user", public;