Closed abitrolly closed 1 year ago
My postgres
user has all the superpowers to do any weird stuff.
# psql -U postgres
psql (10.1)
Type "help" for help.
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
According to this https://stackoverflow.com/questions/36502401/postgres-drop-database-error-pq-cannot-drop-the-currently-open-database/36503031#3650303 attempt to drop connected database will always fail, so need to reconnect to another DB to drop this one. There is always template1
https://www.postgresql.org/docs/current/manage-ag-templatedbs.html but I am not sure every user can connect to it.
This is a bit late. Problem is here:
tracked_databases: ['postgres'] url: 'postgres://postgres@localhost/postgres'
Your tracked_databases
and url
must reference different databases. The url
is the "working" database, which Stellar connects to issue commands. It needs to drop the tracked_databases databases as part of the restore. Thus, it tries to drop the database while it is connected to the same database. That will fail.
Try to change the url
to reference "template1".
@tvuotila is it possible for Stellar to handle that case automatically?
Is template1
accessible to any user?
@tvuotila is it possible for Stellar to handle that case automatically?
I think it kinda does, but the instructions are misleading. For example, following input to stellar init
Please enter the url for your database.
For example:
PostgreSQL: postgresql://localhost:5432/
MySQL: mysql+pymysql://root@localhost/: postgresql://localhost:5432/
You have the following databases: postgres, tvuotila, awesomedb
Please enter the name of the database (eg. projectdb): awesomedb
Please enter your project name (used internally, eg. awesomedb) [awesomedb]:
Wrote stellar.yaml
Tip: You probably want to take a snapshot: stellar snapshot
Will result the following in stellar.yaml
project_name: 'awesomedb'
tracked_databases: ['awesomedb']
url: 'postgresql://localhost:5432/template1'
stellar_url: 'postgresql://localhost:5432/stellar_data'
So, the "Please enter the url for your database." is misleading as it actually means the database server url and should not contain the database name. (You can provide the database name if you want, but it should be different from the tracked databases.) Suggestions for better text are welcome!
Stellar could also show an error if user tries to use the same database in both places.
Is template1 accessible to any user?
Seems like as long as user can create databases, it is accessible (source)
I investigated the code a bit more. Actually, the template1
should be used automatically.
I tested the stellar init
with following input:
Please enter the url for your database.
For example:
PostgreSQL: postgresql://localhost:5432/
MySQL: mysql+pymysql://root@localhost/: postgresql://localhost:5432/awesomedb
Please enter your project name (used internally, eg. awesomedb) [awesomedb]:
Wrote stellar.yaml
Tip: You probably want to take a snapshot: stellar snapshot
stellar.yaml
project_name: 'awesomedb'
tracked_databases: ['awesomedb']
url: 'postgresql://localhost:5432/template1'
stellar_url: 'postgresql://localhost:5432/stellar_data'
Maybe this was fixed at some point.
Maybe this was fixed at some point.
That's good to know. Made a note to myself to check it when I have to touch DB migrations again.
stellar restore
which is run insidepostgres:10.1
docker image fails.Some context
stellar
is a slightly updated version by @maxtacu and mePossible cause
I am not sure if there is a workaround against this. Probably
stellar
should somehow detect if PostgreSQL user doesn't have permissions to issue administrator commands. Not sure how to configure it.@maxtacu any hints?