-
Notifications
You must be signed in to change notification settings - Fork 69
Closed
Labels
@sgrinko
Description
Problem description
На Prod сервере настроил секционирование и спокойно работал и сейчас работаю :)
Понадобилось восстановить БД на другом сервере. Я сделал дамп и восстановил его командами:
time pg_dump --host localhost --port 5432 --username "postgres" --format=plain mkgu_region | gzip > /mnt/pgbak/custom/plain.bak.gz
time gunzip < /mnt/pgbak/custom/plain.bak.gz | psql -U postgres -h localhost mkgu_region2
Всё прошло успешно и БД была восстановлена.
Однако, при попытке выполнить на БД восстановленной из дампа insert получаю...
INSERT INTO base.fact_events(
id, rgu_service_id, rgu_authority_id, fact_vendor_id, status,
created_at, updated_at, deleted_at, event_date, token, mobile,
email, operator_guid)
VALUES (115377903, null, null, 1309, 5,'2018-06-13 12:00:00','2018-06-13 12:00:00', null, '2018-06-13', 'null', '70000000000', null, '9599');
ERROR: attribute 10 of type record has wrong type
DETAIL: Table has type character varying, but query expects date.
********** Error **********
ERROR: attribute 10 of type record has wrong type
SQL state: 42804
Detail: Table has type character varying, but query expects date.
Определение таблицы fact_events
- главная родительская таблица
mkgu_region2=# \d fact_events
Table "base.fact_events"
Column | Type | Collation | Nullable | Default
------------------+-----------------------------+-----------+----------+-----------------------------------------
id | bigint | | not null | nextval('fact_events_id_seq'::regclass)
rgu_service_id | integer | | |
rgu_authority_id | integer | | |
fact_vendor_id | integer | | not null |
status | integer | | |
created_at | timestamp without time zone | | not null | now()
updated_at | timestamp without time zone | | not null |
deleted_at | timestamp without time zone | | |
event_date | date | | not null |
token | character varying(50) | | |
mobile | character varying(25) | | |
email | character varying(128) | | |
operator_guid | character varying(100) | | |
Indexes:
"fact_events_pkey" PRIMARY KEY, btree (id)
"fact_events_event_date_deleted_at_idx" btree (event_date, deleted_at)
"fact_events_updated_at_deleted_at_idx" btree (updated_at, deleted_at)
"index_fact_events_on_deleted_at" btree (deleted_at) WHERE deleted_at IS NOT NULL
"index_fact_events_on_fact_vendor_id" gin (fact_vendor_id)
"index_fact_events_on_rgu_authority_id" gin (rgu_authority_id)
"index_fact_events_on_rgu_service_id" gin (rgu_service_id)
Foreign-key constraints:
"fk_fact_events__fact_vendors" FOREIGN KEY (fact_vendor_id) REFERENCES fact_vendors(id)
"fk_fact_events__rgu_authorities" FOREIGN KEY (rgu_authority_id) REFERENCES rgu_authorities(id)
"fk_fact_events__rgu_services" FOREIGN KEY (rgu_service_id) REFERENCES rgu_services(id)
Number of child tables: 78 (Use \d+ to list them.)
select att.attname,att.atttypid,att.attstattarget,att.attlen,att.attnum,att.attndims,att.attcacheoff,att.atttypmod,att.attbyval,att.attstorage,att.attalign,att.attnotnull,att.atthasdef,att.attidentity,att.attisdropped,att.attislocal,att.attinhcount,att.attcollation,att.attacl,att.attoptions,att.attfdwoptions
FROM pg_attribute AS att
JOIN pg_type AS t ON att.atttypid = t.oid
JOIN pg_class AS tbl ON att.attrelid = tbl.oid
JOIN pg_namespace AS ns ON ns.oid = tbl.relnamespace
WHERE att.attnum > 0 AND tbl.relkind = 'r' and ns.nspname = 'base' AND tbl.relname = 'fact_events'
order by att.attnum;
attname | atttypid | attstattarget | attlen | attnum | attndims | attcacheoff | atttypmod | attbyval | attstorage | attalign | attnotnull | atthasdef | attidentity | attisdropped | attislocal | attinhcount | attcollation | attacl | attoptions | attfdwoptions
------------------+----------+---------------+--------+--------+----------+-------------+-----------+----------+------------+----------+------------+-----------+-------------+--------------+------------+-------------+--------------+--------+------------+---------------
id | 20 | -1 | 8 | 1 | 0 | -1 | -1 | t | p | d | t | t | | f | t | 0 | 0 | | |
rgu_service_id | 23 | -1 | 4 | 2 | 0 | -1 | -1 | t | p | i | f | f | | f | t | 0 | 0 | | |
rgu_authority_id | 23 | -1 | 4 | 3 | 0 | -1 | -1 | t | p | i | f | f | | f | t | 0 | 0 | | |
fact_vendor_id | 23 | -1 | 4 | 4 | 0 | -1 | -1 | t | p | i | t | f | | f | t | 0 | 0 | | |
status | 23 | -1 | 4 | 5 | 0 | -1 | -1 | t | p | i | f | f | | f | t | 0 | 0 | | |
created_at | 1114 | -1 | 8 | 7 | 0 | -1 | -1 | t | p | d | t | t | | f | t | 0 | 0 | | |
updated_at | 1114 | -1 | 8 | 8 | 0 | -1 | -1 | t | p | d | t | f | | f | t | 0 | 0 | | |
deleted_at | 1114 | -1 | 8 | 9 | 0 | -1 | -1 | t | p | d | f | f | | f | t | 0 | 0 | | |
event_date | 1082 | -1 | 4 | 10 | 0 | -1 | -1 | t | p | i | t | f | | f | t | 0 | 0 | | |
token | 1043 | -1 | -1 | 11 | 0 | -1 | 54 | f | x | i | f | f | | f | t | 0 | 100 | | |
mobile | 1043 | -1 | -1 | 12 | 0 | -1 | 29 | f | x | i | f | f | | f | t | 0 | 100 | | |
email | 1043 | -1 | -1 | 13 | 0 | -1 | 132 | f | x | i | f | f | | f | t | 0 | 100 | | |
operator_guid | 1043 | -1 | -1 | 14 | 0 | -1 | 104 | f | x | i | f | f | | f | t | 0 | 100 | | |
(13 rows)
Определение таблицы fact_events_78
именно сюда должна идти вставка
mkgu_region2=# \d fact_events_78
Table "base.fact_events_78"
Column | Type | Collation | Nullable | Default
------------------+-----------------------------+-----------+----------+-----------------------------------------
id | bigint | | not null | nextval('fact_events_id_seq'::regclass)
rgu_service_id | integer | | |
rgu_authority_id | integer | | |
fact_vendor_id | integer | | not null |
status | integer | | |
created_at | timestamp without time zone | | not null | now()
updated_at | timestamp without time zone | | not null |
deleted_at | timestamp without time zone | | |
event_date | date | | not null |
token | character varying(50) | | |
mobile | character varying(25) | | |
email | character varying(128) | | |
operator_guid | character varying(100) | | |
Indexes:
"fact_events_78_pkey" PRIMARY KEY, btree (id)
"fact_events_78_deleted_at_idx" btree (deleted_at) WHERE deleted_at IS NOT NULL
"fact_events_78_event_date_deleted_at_idx" btree (event_date, deleted_at)
"fact_events_78_fact_vendor_id_idx" gin (fact_vendor_id)
"fact_events_78_rgu_authority_id_idx" gin (rgu_authority_id)
"fact_events_78_rgu_service_id_idx" gin (rgu_service_id)
"fact_events_78_updated_at_deleted_at_idx" btree (updated_at, deleted_at)
Check constraints:
"pathman_fact_events_78_check" CHECK (event_date >= '2018-06-01'::date AND event_date < '2018-07-01'::date)
Foreign-key constraints:
"fact_events_78_fact_vendor_id_fkey" FOREIGN KEY (fact_vendor_id) REFERENCES fact_vendors(id)
"fact_events_78_rgu_authority_id_fkey" FOREIGN KEY (rgu_authority_id) REFERENCES rgu_authorities(id)
"fact_events_78_rgu_service_id_fkey" FOREIGN KEY (rgu_service_id) REFERENCES rgu_services(id)
Inherits: fact_events
select att.attname,att.atttypid,att.attstattarget,att.attlen,att.attnum,att.attndims,att.attcacheoff,att.atttypmod,att.attbyval,att.attstorage,att.attalign,att.attnotnull,att.atthasdef,att.attidentity,att.attisdropped,att.attislocal,att.attinhcount,att.attcollation,att.attacl,att.attoptions,att.attfdwoptions
FROM pg_attribute AS att
JOIN pg_type AS t ON att.atttypid = t.oid
JOIN pg_class AS tbl ON att.attrelid = tbl.oid
JOIN pg_namespace AS ns ON ns.oid = tbl.relnamespace
WHERE att.attnum > 0 AND tbl.relkind = 'r' and ns.nspname = 'base' AND tbl.relname = 'fact_events_78'
order by att.attnum;
attname | atttypid | attstattarget | attlen | attnum | attndims | attcacheoff | atttypmod | attbyval | attstorage | attalign | attnotnull | atthasdef | attidentity | attisdropped | attislocal | attinhcount | attcollation | attacl | attoptions | attfdwoptions
------------------+----------+---------------+--------+--------+----------+-------------+-----------+----------+------------+----------+------------+-----------+-------------+--------------+------------+-------------+--------------+--------+------------+---------------
id | 20 | -1 | 8 | 1 | 0 | -1 | -1 | t | p | d | t | t | | f | f | 1 | 0 | | |
rgu_service_id | 23 | -1 | 4 | 2 | 0 | -1 | -1 | t | p | i | f | f | | f | f | 1 | 0 | | |
rgu_authority_id | 23 | -1 | 4 | 3 | 0 | -1 | -1 | t | p | i | f | f | | f | f | 1 | 0 | | |
fact_vendor_id | 23 | -1 | 4 | 4 | 0 | -1 | -1 | t | p | i | t | f | | f | f | 1 | 0 | | |
status | 23 | -1 | 4 | 5 | 0 | -1 | -1 | t | p | i | f | f | | f | f | 1 | 0 | | |
created_at | 1114 | -1 | 8 | 6 | 0 | -1 | -1 | t | p | d | t | t | | f | f | 1 | 0 | | |
updated_at | 1114 | -1 | 8 | 7 | 0 | -1 | -1 | t | p | d | t | f | | f | f | 1 | 0 | | |
deleted_at | 1114 | -1 | 8 | 8 | 0 | -1 | -1 | t | p | d | f | f | | f | f | 1 | 0 | | |
event_date | 1082 | -1 | 4 | 9 | 0 | -1 | -1 | t | p | i | t | f | | f | f | 1 | 0 | | |
token | 1043 | -1 | -1 | 10 | 0 | -1 | 54 | f | x | i | f | f | | f | f | 1 | 100 | | |
mobile | 1043 | -1 | -1 | 11 | 0 | -1 | 29 | f | x | i | f | f | | f | f | 1 | 100 | | |
email | 1043 | -1 | -1 | 12 | 0 | -1 | 132 | f | x | i | f | f | | f | f | 1 | 100 | | |
operator_guid | 1043 | -1 | -1 | 13 | 0 | -1 | 104 | f | x | i | f | f | | f | f | 1 | 100 | | |
(13 rows)
mkgu_region2=#
Смотрим настройки партицирования
mkgu_region2=# select * from public.pathman_config;
partrel | expr | parttype | range_interval | cooked_expr
-------------+------------+----------+----------------+---------------------------------------------------------------------------------------------------------------------------
fact_events | event_date | 2 | 1 mon | {VAR :varno 1 :varattno 10 :vartype 1082 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 10 :location 8}
fact_rates | event_date | 2 | 1 mon | {VAR :varno 1 :varattno 11 :vartype 1082 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 11 :location 8}
(2 rows)
Time: 8.081 ms
mkgu_region2=# select * from public.pathman_config_params;
partrel | enable_parent | auto | init_callback | spawn_using_bgw
-------------+---------------+------+---------------+-----------------
fact_events | t | t | | f
fact_rates | t | t | | f
(2 rows)
mkgu_region2=# SELECT * FROM pathman_partition_list;
parent | partition | parttype | expr | range_min | range_max
-------------+----------------+----------+------------+------------+------------
fact_events | fact_events_1 | 2 | event_date | 2012年01月01日 | 2012年02月01日
fact_events | fact_events_2 | 2 | event_date | 2012年02月01日 | 2012年03月01日
...
fact_events | fact_events_75 | 2 | event_date | 2018年03月01日 | 2018年04月01日
fact_events | fact_events_76 | 2 | event_date | 2018年04月01日 | 2018年05月01日
fact_events | fact_events_77 | 2 | event_date | 2018年05月01日 | 2018年06月01日
fact_events | fact_events_78 | 2 | event_date | 2018年06月01日 | 2018年07月01日
Обратил внимание на {VAR :varno 1 :varattno 10
под 10-ым номером идёт поле token
может в этом и проблема?
непонятно как тогда это всё работает на данный момент на prod сервере...
Что скажете? Что делать?
Environment
использую ванильную версию 10.4
# lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 6.9 (Santiago)
Release: 6.9
Codename: Santiago
#
# uname -a
Linux *.*.* 2.6.32-696.20.1.el6.x86_64 #1 SMP Fri Jan 12 15:07:59 EST 2018 x86_64 x86_64 x86_64 GNU/Linux
#
mkgu_region2=# SELECT * FROM pg_extension;
extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition
--------------------+----------+--------------+----------------+------------+---------------------+--------------
plpgsql | 10 | 11 | f | 1.0 | |
adminpack | 10 | 11 | f | 1.1 | |
btree_gin | 10 | 2200 | t | 1.2 | |
citext | 10 | 2200 | t | 1.4 | |
dblink | 10 | 2200 | t | 1.2 | |
pageinspect | 10 | 2200 | t | 1.6 | |
pg_buffercache | 10 | 2200 | t | 1.3 | |
pg_grab_statement | 10 | 17255359 | f | 1.0 | |
pg_pathman | 10 | 2200 | f | 1.4 | {17255925,17255936} | {"",""}
pg_prewarm | 10 | 2200 | t | 1.1 | |
pg_stat_statements | 10 | 2200 | t | 1.5 | |
pg_trgm | 10 | 2200 | t | 1.3 | |
pg_tsparser | 10 | 2200 | t | 1.0 | |
pgstattuple | 10 | 2200 | t | 1.5 | |
postgres_fdw | 10 | 2200 | t | 1.0 | |
uuid-ossp | 10 | 2200 | t | 1.1 | |
(16 rows)
Time: 3.039 ms
mkgu_region2=#
mkgu_region2=# SELECT version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 10.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18), 64-bit
(1 row)
Time: 0.268 ms
mkgu_region2=#
mkgu_region2=# SELECT get_pathman_lib_version();
get_pathman_lib_version
-------------------------
10410
(1 row)
Time: 0.608 ms
mkgu_region2=#