This question has been flagged
4 Replies
23451 Views

I installed a fresh Odoo and created a DataBase, installed all modules I need and made the admin an admin.

Now I want to duplicate this db, but I always get "Database is being accessed by other users".

How can I duplicate a database with the database manager GUI of odoo?

If I stop odoo service the simple line of sql does the job:

CREATE DATABASE whatever_db WITH TEMPLATE base_deb OWNER db_owner;

If it isn't possible without entering a console, what use does this function have at all?

Thx Peter

Avatar
Discard
Best Answer

This is due to postgres keeping track of the connections, even if they are not closed correctly (just killing the browser for example). Probably the thing to do is restart Odoo. Right after that, the connections should be gone and you should be able to duplicate.

For some mysterious reason it sometimes works over here after pressing the button multiple times. I am clueless as to why that is.

By the way, the client-dump of the database is not always fool-proof we have found out. I still rely on the pg_dump, if only to ensure the type of dump and the other options such as the no-owner flag. Furthermore, when using legacy postgres to update to a new postgres, the client will not do the job correctly.

Avatar
Discard
Best Answer

Hello

You Can restart postgres service.
 

Avatar
Discard
Author

with postgres I know what to do ... stop odoo, enter postgres, duplicate ... but that's not using the database manager of odoo! And what use of a database manager if I have to restart the underlying database?

you can use this command: ps -ax | grep server. you get list process name. then you kill process the command is : kill -9 [proces_name].

Author

thx, I know how to do this, of you can use top or htop or whatever! but how to do it WITHOUT ENTERING THE CONSOLE? If I use the console, there is no use of the database manager gui of odoo!

Best Answer

That is a good question and I guess there's no answer for that, no answer like you want.

Like you want, only wait for Oddo disconnect from db and after you can do database operations.

After some time testing and using Odoo, I think the "database manager" feature needs more work.

I can only do database operations after use SQL query to postgresql disconnect any user from specific database which I'll work.
Here the query useful sometimes, to kill connections: 

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'database_name'
  AND pid <> pg_backend_pid();

Change 'database_name' for your needs and all connections to db will be closed.

 

Avatar
Discard
Author

thx ... if I stop odoo, the simple line CREATE DATABASE whatever_db WITH TEMPLATE base_db OWNER username; works for me ...

If you are in multi user environment you'll need this query. You'll execute query CREATE DATABASE..TEMPLATE, why not execute before and kill all connections to specific db? Thanks for your comment.

I give to you the only answer as you ask for, you don't need to enter in console you only need psql or any connections to postgresql.