Open toutas opened 3 months ago
@toutas when restoring from a dump you should put the instance in the restoring
mode. Have a look the documentation: https://docs.timescale.com/migrate/latest/pg-dump-and-restore/
@toutas when restoring from a dump you should put the instance in the
restoring
mode. Have a look the documentation: https://docs.timescale.com/migrate/latest/pg-dump-and-restore/
I did end up doing that, but it makes no difference.
I fixed it by running pg_restore -f -
to pipe the output to sed
and remove all ONLY
occurences for hypertables sed "s/ONLY {{ hypertable }}/{{ hypertable }}/g"
still think it should be documented that this is necessary
@toutas when restoring from a dump you should put the instance in the
restoring
mode. Have a look the documentation: https://docs.timescale.com/migrate/latest/pg-dump-and-restore/I did end up doing that, but it makes no difference.
I fixed it by running
pg_restore -f -
to pipe the output tosed
and remove allONLY
occurences for hypertablessed "s/ONLY {{ hypertable }}/{{ hypertable }}/g"
still think it should be documented that this is necessary
The safe and correct way (as the document link I've sent before) is do something like:
psql -d your_database -c 'SELECT timescaledb_pre_restore();'
pg_restore ...
psql -d your_database -c 'SELECT timescaledb_post_restore();'
@toutas you need to pay attention to run the "pre" and "post" restore commands into the same database you'll restore your database.
@toutas when restoring from a dump you should put the instance in the
restoring
mode. Have a look the documentation: https://docs.timescale.com/migrate/latest/pg-dump-and-restore/I did end up doing that, but it makes no difference. I fixed it by running
pg_restore -f -
to pipe the output tosed
and remove allONLY
occurences for hypertablessed "s/ONLY {{ hypertable }}/{{ hypertable }}/g"
still think it should be documented that this is necessaryThe safe and correct way (as the document link I've sent before) is do something like:
1. Put your database into the restoring mode:
psql -d your_database -c 'SELECT timescaledb_pre_restore();'
2. Run the restore:
pg_restore ...
3. Put back your database into the normal mode:
psql -d your_database -c 'SELECT timescaledb_post_restore();'
I am well aware of the safe and correct way as I mentioned, I am already doing it. It does not fix the issue at hand though, so not sure why you are pointing it out?
This is the command I am running when restoring. without sed
to remove ONLY
keyword from DDL touching hypertables it does not work. If I remove that part it fails restoring with the errors mentioned in my main issue post.
@fabriziomello
so what you are saying is I need to run it not on the initial postgres database, but create my target database before restoring?
so what you are saying is I need to run it not on the initial postgres database, but create my target database before restoring?
Exactly... because this "timescaledb_pre_restore()" will disable timescaledb hooks in order to don't raise exceptions on the statements that are failing during the restore. In a normal operation those statements are blocked by timescaledb.
so what you are saying is I need to run it not on the initial postgres database, but create my target database before restoring?
Exactly... because this "timescaledb_pre_restore()" will disable timescaledb hooks in order to don't raise exceptions on the statements that are failing during the restore. In a normal operation those statements are blocked by timescaledb.
Fair, I will try it out and confirm it fixes the issue.
Normally pg_dump and pg_restore do not require the target database to be present, so would be nice with a notice in the documentation to people using the --create
flag like I am for restoring to fresh instances.
Normally pg_dump and pg_restore do not require the target database to be present, so would be nice with a notice in the documentation to people using the
--create
flag like I am for restoring to fresh instances.
I know but unfortunately the pg_dump
options --create
and --clean
will not work properly with timescaledb... this is another advice for you to don't use it and manually create the new target database.
What type of bug is this?
Unexpected error
What subsystems and features are affected?
Backup, Partitioning, Restore
What happened?
When I pg_dump my selfhosted database that contains many tables along with one single hypertable which was generated using
with the following pg_dump command
the generated dump throws errors during restore with pg_restore regarding the
ONLY
keyword. Here is an excerpt:I have been looking around for documentation to determine if I am doing something wrong, or if this way of performing backup/restore is just not supported? The backup and restore docs mention using pg_dump and pg_restore, so I am wondering why this is not working or does not have any documentation to point out backups should not be done this way with timescaledb.
At this point I assume the best practice would be to generate directory dump and use sed to remove all occurences of only, but I hope if that is the recommended approach it will be documented somewhere as it seems like a bug that pg_dump/pg_restore is recommended but not quite working.
TimescaleDB version affected
2.15.3
PostgreSQL version used
PostgreSQL 16.3 (Ubuntu 16.3-1.pgdg22.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
What operating system did you use?
Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-189-generic x86_64)
What installation method did you use?
Docker
What platform did you run on?
On prem/Self-hosted, Other
Relevant log output and stack trace
How can we reproduce the bug?
I have not attempted to reproduce it from scratch in an empty database, but I can reproduce the bug from my existing database not containing any hypertables. I am using the docker image timescale/timescaledb-ha:pg16.3-ts2.15.3.
converting an existing table to a hypertable using the command
dump the complete database containing the hypertable with the following pg_dump flags
on a new fresh postgres container with the backup.dump file present in the data directory run
the errors are then generated