# How to properly import a database

**URL:** https://discuss.tryton.org/t/how-to-properly-import-a-database/6748
**Category:** System Administrator
**Created:** [December 1, 2023, 11:22am UTC](https://discuss.tryton.org/t/how-to-properly-import-a-database/6748 "2023-12-01T11:22:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![herrdeh](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/herrdeh/32/821_2.png) [@herrdeh](https://discuss.tryton.org/u/herrdeh)
#### Post date: [December 1, 2023, 11:22am UTC](https://discuss.tryton.org/t/how-to-properly-import-a-database/6748/1 "2023-12-01T11:22:53Z")

</div>

When importing a database dump by something like

`psql -d database_name < DB_dump_name.sql`

in ubuntu and debian I get the error message:

`$ psql -U DB_user -d database_name < DB_dump_name.sql psql: error: connection server to Socket »/var/run/postgresql/.s.PGSQL.5432« failed: FATAL: Peer authentication failed for user "DB_user" `

This can be fixed by changing in `/etc/postgresql/<your-version>/main/pg_hba.conf`

`local	all	all	peer`

to

`local	all	all	md5`

But this solution may have security concerns, is difficult to handle within an install script and may be confusing when (as in my system) there are various postgres versions.

In priciple, this can be solved by doing the dump import by the ‘postgres’ user:

`sudo -u postgres -- psql -d database_name < DB_dump_name.sql`

Problem is that the the `trytond-admin [...] --all` command then fails with

`psycopg2.errors.DuplicateTable: relation "ir_configuration_id_seq" already exists`.

We discussed that problem broadly [here](https://discuss.tryton.org/t/database-restore-problem/4992), but I now do notice that those days I avoided the problem by changing pg\_hba.conf.

Do we have a proper solution with a better pqsl import command? @edbo, guess this is your playground… (;

Cheers,  
Wolf

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [December 1, 2023, 11:37am UTC](https://discuss.tryton.org/t/how-to-properly-import-a-database/6748/2 "2023-12-01T11:37:09Z")

</div>

> [@herrdeh](#):
>
> Do we have a proper solution with a better pqsl import command? @edbo, guess this is your playground… (;

Yeay!! I love it playing around with that stuff 💪 and help people.

> [@herrdeh](#):
>
> psql -U DB\_user -d database\_name \< DB\_dump\_name.sql

Add `-h localhost` to the command so no changes are needed in the `pg_hba.conf`.

`psql -U DB_user -d database_name -h localhost < DB_dump_name.sql`

---

<div class="post-metadata">

### Author: ![herrdeh](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/herrdeh/32/821_2.png) [@herrdeh](https://discuss.tryton.org/u/herrdeh)
#### Post date: [December 2, 2023, 2:59pm UTC](https://discuss.tryton.org/t/how-to-properly-import-a-database/6748/3 "2023-12-02T14:59:45Z")

</div>

This seems to work very well - and as so often, Mr. Eddy is my personal hero of the day (;  
Thank you, my friend!

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [December 3, 2023, 3:00am UTC](https://discuss.tryton.org/t/how-to-properly-import-a-database/6748/4 "2023-12-03T03:00:34Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
