[Docs] Migrating from SQLite to PostgreSQL
pgloader
Migrate from SQLite to PostgreSQL withSQLite is the default database engine, mainly for development purpose but it should be enough for small instance. If you want to migrate to PostgreSQL afterward you can follow theses steps (Debian based):
-
Install and configure PostgreSQL, create a new database (ex...
hiboo
) with the right owner if you don't usepostgres
: help -
install pgloader: https://pgloader.readthedocs.io
apt install pgloader
- by default pgloader convert
datetime
totimestamptz
and it raise error on hiboo so create pgloader command-file/tmp/pgloader-hiboo.conf
:
LOAD database
FROM sqlite:///tmp/hiboo.db
INTO postgresql:///hiboo
CAST type datetime to timestamp using sqlite-timestamp-to-timestamp;
- shutdown hiboo to avoid data loss during migration
service hiboo stop # if you created systemd file
- backup your sqlite file
cp hiboo.db hiboo.db.bak
- make sure
postgres
user can read the SQlite db and the pgloader config file:
chown postgres:postgres /tmp/hiboo.db
chown postgres:postgres /tmp/pgloader-hiboo.conf
- import
sudo -u postgresql pgloader /tmp/pgloader-hiboo.conf
- If you created specific user you will probably need to set the right owner:
su - postgres psql <dbname>
then inside psql:
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO <username>;
<CTRL-D>
to exit
- don't forget to setup SQLAlchemy with the right URI
SQLALCHEMY_DATABASE_URI='postgres://<dbuser>:<password>@localhost:5432/<dbname>'
- Restart hiboo, check if it works and clean the mess!
If it's fail restore the SQLite backup file and database URI configuration.