Answer the question
In order to leave comments, you need to log in
How to restore a database from a PostgreSQL backup on Linux?
The problem is, I created a backup using pgAdmin. I'm trying to restore this database on a VPS server.
BUT at me only tables, without the data are created.
I tried the options: pg_restore -c -i -U postgres -d merch_telegram_bot_db test.backup -W
pg_restore --dbname=merch_telegram_bot_db --section=pre-data --jobs=4 test.backup
pg_restore -h localhost -p 5432 -U postgres -d merch_telegram_bot_db -v "/usr/local/bin/bot/test.backup"
and a bunch of other options, I don't understand what the problem is.
Tell me how to implement all this, or how to import data from CSV files into database tables using linux.
Errors while restoring a backup.
In this version, I used the command:
pg_restore -h localhost -p 5432 -U postgres -d merch_telegram_bot_db -v "/usr/local/bin/bot/test.backup"
pg_restore: from TOC entry 3036; 0 108349 TABLE DATA category postgres
pg_restore: error: COPY failed for table "category": ERROR: character with byte sequence 0xd0 0x91 in encoding "UTF8" has no equivalent in encoding "LATIN1"
CONTEXT: COPY category, line 1
pg_restore: error: COPY failed for table "product": ERROR: character with byte sequence 0xd0 0x9c in encoding "UTF8" has no equivalent in encoding "LATIN1"
CONTEXT: COPY product, line 1
pg_restore: error: could not execute query: ERROR: insert or update on table "product_photo" violates foreign key constraint "
DETAIL: Key (product_id)=(1) is not present in table "product".
Command was: ALTER TABLE ONLY public.product_photo
ADD CONSTRAINT product_photo_product_id_fkey FOREIGN KEY (product_id) REFERENCES public.product(product_id);
Answer the question
In order to leave comments, you need to log in
In my case, the answer to the question on stackoverflow helped: https://stackoverflow.com/questions/13115692/encod...
I am answering this because nothing from StackOverFlow worked for me.
I combined two solutions from other sites that did the job (this answer works for Ubuntu server 12.04 and PGSQL 9.1):
Create a file:
nano /etc/profile.d/lang.sh
Add the following
export LANGUAGE="en_US.UTF- 8"
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
Save it
Restart shell or run all export commands manually in current shell instance
Reconfigure so the encoding can be UTF8 ([got it from here] [1])
sudo su postgres
psql
update pg_database set datistemplate=false where datname='template1';
drop database Template1;
create database template1 with owner=postgres encoding='UTF-8'
lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
update pg_database set datistemplate=true where datname='template1';
Use template1 for db creation.
I hope this helps ;)
DROP DATABASE merch_telegram_bot_db;
CREATE DATABASE merch_telegram_bot_db ENCODING 'UTF8';
pg_restore -h localhost -p 5432 -U postgres -d merch_telegram_bot_db -v "/usr/local/bin/bot/test.backup"
Don't do anything harder than selecting through a vermord, or better yet, throw it out altogether.
pg_dump -U postgres -Fc merch_telegram_bot_db > test.backup
createdb -U postgres -E UNICODE merch_telegram_bot_db
pg_restore -U postgres -j 2 -d merch_telegram_bot_db test.backup
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question