Sometimes (especially for large dbs) we need to import the postgres dump directly in the db, this can be done easily in bash as follows.
Pre-requisites
login access to postgres with the odoo user
a bash shell
Notes
$DB_USER: odoo database user
$LOCAL_DBNAME: name of the local db where the dump will be imported
$SQLFILE: sql dump file
Importing the dump
Create a new db as the odoodb user:
> createdb --host=localhost --username="$DB_USER" "$LOCAL_DBNAME"Restore the database from the sql dump:
> psql --host=localhost --username="$DB_USER" "$LOCAL_DBNAME" < "$SQLFILE"[OPTIONAL] Copy the filestore (if available) in a new directory called $LOCAL_DBNAME in the datadir path
Clean-up production data:
Delete all smtp servers:
> psql --host=localhost --username="$DB_USER" --dbname "$LOCAL_DBNAME" << EOF
DELETE FROM ir_mail_server WHERE "name" != 'localhost'
EOFReset admin password to 'admin':
> python_code="from passlib.context import CryptContext
print CryptContext(['pbkdf2_sha512']).encrypt('admin')"
crypt_pass=$(python -c "$python_code")
> psql --host=localhost --username="$DB_USER" --dbname "$LOCAL_DBNAME" << EOF
update res_users set password_crypt = '${crypt_pass}' where id = 2;
EOF
NOTE:if odoo version <12 then use id = 1Change database UUID:
> new_uuid=$(uuidgen)
> psql --host=localhost --username="$DB_USER" --dbname "$LOCAL_DBNAME" << EOF
Update ir_config_parameter set value = '${new_uuid}' WHERE KEY='database.uuid';
EOF