dokku / dokku-postgres

a postgres plugin for dokku
MIT License
484 stars 97 forks source link

postgres:import importing to public schema not the db schema. #218

Closed jacstrong closed 3 years ago

jacstrong commented 3 years ago

Description of problem

I exported a database using dokku postgres:export dbname and imported it to another instance using dokku postgres:import dbname. The application running on the new instance does not connect correctly to the new imported database. It is connecting to the database itself, but the data is not there. I entered connected to both instances. Running \l both were identical. However when I run \dt is where the difference is.

Actual Results

// On the new instance
=# \dt 
                 List of relations
 Schema |          Name          | Type  |  Owner
--------+------------------------+-------+----------
 public | document               | table | postgres
...
// On the original instance
=# \dt 
                 List of relations
 Schema |          Name          | Type  |  Owner
--------+------------------------+-------+----------
 dbname | document               | table | postgres
...

The data was moved over, but is is the public schema (I think). Running select queries gives me different results as well.

// Original machine
SELECT * FROM document;
// Returns the data

SELECT * FROM dbname.document;
// Also returns the data

// New machine
SELECT * FROM document;
// Empty result

SELECT * FROM dbname.document;
// Returns the data

Expected Results

I guess I would expect that exporting from one db and importing to another with the same name would produce nearly identical instances. Any help here would be great. Everything else is working great in the app, it connects to the db, but returns no data.

josegonzalez commented 3 years ago

Okay so here is what currently happens on master:

root@bc5d31be11c3:/workspaces/postgres# dokku postgres:export test > test-export
root@bc5d31be11c3:/workspaces/postgres# dokku postgres:create new-database
       Waiting for container to be ready
       Creating container database
       Securing connection to database
=====> Postgres container created: new-database
=====> new-database postgres service information
       Config dir:          /var/lib/dokku/services/postgres/new-database/data
       Config options:                               
       Data dir:            /var/lib/dokku/services/postgres/new-database/data
       Dsn:                 postgres://postgres:95be1d9dd6d0759c927b34e7d33da6a2@dokku-postgres-new-database:5432/new_database
       Exposed ports:       -                        
       Id:                  464d8b4b17950afa2fcf21ab1cc6e81608f9082f69efa2b1708d93d64c95d51f
       Internal ip:         172.17.0.4               
       Links:               -                        
       Service root:        /var/lib/dokku/services/postgres/new-database
       Status:              running                  
       Version:             postgres:13.4            
root@bc5d31be11c3:/workspaces/postgres# dokku postgres:import new-database <test-export 
root@bc5d31be11c3:/workspaces/postgres# dokku postgres:connect new-database
psql (13.4 (Debian 13.4-1.pgdg100+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

new_database=# \l
                                  List of databases
     Name     |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges   
--------------+----------+----------+------------+------------+-----------------------
 new_database | postgres | UTF8     | en_US.utf8 | en_US.utf8 | 
 postgres     | postgres | UTF8     | en_US.utf8 | en_US.utf8 | 
 template0    | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
              |          |          |            |            | postgres=CTc/postgres
 template1    | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
              |          |          |            |            | postgres=CTc/postgres
(4 rows)

new_database=# select * from documents;
ERROR:  relation "documents" does not exist
LINE 1: select * from documents;

new_database=# select * from test.documents;
 id | name | age |                      address                       | salary 
----+------+-----+----------------------------------------------------+--------
  1 | Paul |  32 | California                                         |  20000
(1 row)

new_database=# \dt
Did not find any relations.
new_database=# \dt test.
           List of relations
 Schema |   Name    | Type  |  Owner   
--------+-----------+-------+----------
 test   | documents | table | postgres
(1 row)

new_database=# \dn
  List of schemas
  Name  |  Owner   
--------+----------
 public | postgres
 test   | postgres
(2 rows)

new_database=# 

Seems like:

I think that is what you expect, so this should be working now? If I misunderstood or if thats not what you expect, feel free to comment on the issue/reopen and we'll go from there.