Migrating data to TimescaleDB from a different PostgreSQL database
You can migrate your data into TimescaleDB from a different PostgreSQL database.
To migrate between TimescaleDB databases, for example from self-hosted TimescaleDB to Timescale Cloud, see the guide to migrating your TimescaleDB database to Cloud.
Before you begin, check that you have:
- Installed and set up TimescaleDB within your PostgreSQL instance
- Installed the PostgreSQL
- Installed a client for connecting to PostgreSQL. These instructions use
psql, but any client works.
Migrate your data into TimescaleDB from a different PostgreSQL database.
Migrating your data into TimescaleDB
Copy the database schema from your source database into a backup file named
source_db.bak. This file contains the SQL commands to recreate all the tables in your source database.
pg_dump --schema-only -f source_db.bak <SOURCE_DB_NAME>
Recreate these tables in your destination database by copying out of the
psql -d <DESTINATION_DB_NAME> < source_db.bak
Connect to your destination database.
psql -d <DESTINATION_DB_NAME>
Turn tables that contain time-series data into hypertables by using the
create_hypertablefunction. This function must be run on a table while it's empty. For example, for a time-series table named
timeas its time partitioning column, run:
\SELECT create_hypertable('conditions', 'time');
Copy the data from your source database table into a
psql -d <SOURCE_DB_NAME> -c "\COPY (SELECT * FROM <TABLE_NAME>) TO <FILENAME>.csv DELIMITER ',' CSV"
Repeat for any other tables in your database.
Insert the data from the
.csvinto your destination database's hypertables. For detailed instructions, see the CSV import guide.
To learn what you can do with your hypertable data, read about common hypertable commands.
Found an issue on this page?Report an issue!