Repository navigation
Description
pgloader version is 3.6.9 running on Ubuntu 24.04:
% pgloader --version
pgloader version "3.6.9"
compiled with SBCL 2.2.9.debian
% lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04 LTS
Release: 24.04
Codename: noble
I use it to migrate from an SQLite3 database of 1.6GB in size to a PostgreSQL server. It starts running but it hangs and does not progress.
PostgreSQL version is 16.4 running on Rocky Linux 9; SQLite 3 version is 3.45.1.
My pgloader configuration file is:
% cat pgloader.migrate2PostgreSQL.load
load database
from sqlite://db/db.sqlite3
into postgres://franzy@rachel/franzydb
with include drop, create tables, create no indexes, reset sequences
, workers = 2, concurrency = 1
, on error stop
, batch rows = 1000
set work_mem to '64MB', maintenance_work_mem to '512 MB';
I invoke it as follows (output shown):
% pgloader -v pgloader.migrate2PostgreSQL.load
2024-11-07T11:10:26.002000+01:00 NOTICE Starting pgloader, log system is ready.
2024-11-07T11:10:26.007000+01:00 LOG pgloader version "3.6.9"
2024-11-07T11:10:26.009000+01:00 LOG Parsing commands from file #P"/home/luca/git/fluca1978/franzy/pgloader.migrate2PostgreSQL.load"
2024-11-07T11:10:26.111002+01:00 LOG Migrating from #<SQLITE-CONNECTION sqlite:///home/luca/git/fluca1978/franzy/db/db.sqlite3 {10068A3ED3}>
2024-11-07T11:10:26.112002+01:00 LOG Migrating into #<PGSQL-CONNECTION pgsql://franzy@rachel:5432/franzydb {10068A4063}>
2024-11-07T11:10:26.130002+01:00 NOTICE SQLite column django_migrations.id uses a sequence
2024-11-07T11:10:26.130002+01:00 NOTICE SQLite column django_content_type.id uses a sequence
2024-11-07T11:10:26.131002+01:00 NOTICE SQLite column auth_group_permissions.id uses a sequence
2024-11-07T11:10:26.131002+01:00 NOTICE SQLite column auth_user_groups.id uses a sequence
2024-11-07T11:10:26.131002+01:00 NOTICE SQLite column auth_user_user_permissions.id uses a sequence
2024-11-07T11:10:26.131002+01:00 NOTICE SQLite column auth_permission.id uses a sequence
2024-11-07T11:10:26.131002+01:00 NOTICE SQLite column auth_group.id uses a sequence
2024-11-07T11:10:26.131002+01:00 NOTICE SQLite column franzy_userinfo.id uses a sequence
2024-11-07T11:10:26.131002+01:00 NOTICE SQLite column eventi.id uses a sequence
2024-11-07T11:10:26.131002+01:00 NOTICE SQLite column django_admin_log.id uses a sequence
2024-11-07T11:10:26.132002+01:00 NOTICE SQLite column tutor_riscontroattivita.id uses a sequence
2024-11-07T11:10:26.132002+01:00 NOTICE SQLite column auth_user.id uses a sequence
2024-11-07T11:10:26.133002+01:00 NOTICE SQLite column esse3_db_sync.pk uses a sequence
2024-11-07T11:10:26.133002+01:00 NOTICE SQLite column tutor_categoriaattivita.id uses a sequence
2024-11-07T11:10:26.133002+01:00 NOTICE SQLite column tutor_attivita.id uses a sequence
2024-11-07T11:10:26.133002+01:00 NOTICE SQLite column studente_foto.id uses a sequence
2024-11-07T11:10:26.152002+01:00 NOTICE Prepare PostgreSQL database.
2024-11-07T11:10:27.087018+01:00 NOTICE COPY docenti with 0 rows estimated [1/2]
2024-11-07T11:10:27.125019+01:00 NOTICE COPY docente_corso_di_laurea with 0 rows estimated [1/2]
2024-11-07T11:10:27.129019+01:00 NOTICE COPY corsi_di_studio with 0 rows estimated [1/2]
2024-11-07T11:10:27.133019+01:00 NOTICE COPY percorsi with 0 rows estimated [1/2]
2024-11-07T11:10:27.137019+01:00 NOTICE COPY ordinamenti with 0 rows estimated [1/2]
2024-11-07T11:10:27.140019+01:00 NOTICE COPY studenti with 0 rows estimated [1/2]
2024-11-07T11:10:29.128052+01:00 NOTICE COPY maturita with 0 rows estimated [1/2]
2024-11-07T11:10:29.403057+01:00 ERROR Error while formatting a row from "maturita":
2024-11-07T11:10:29.403057+01:00 ERROR The value
6.25d0
is not of type
(OR STRING NULL FIXNUM)
when binding PGLOADER.TRANSFORMS::INTEGER-STRING
2024-11-07T11:10:29.404057+01:00 ERROR The value
NIL
is not of type
NUMBER
2024-11-07T11:10:29.405057+01:00 WARNING PostgreSQL warning: there is no transaction in progress
At this point, the program is stuck. On the PostgreSQL side, I see there is no activity (apparently):
franzydb=# select datname, query, wait_event, wait_event_type from pg_stat_activity where datname = 'franzydb';
-[ RECORD 1 ]---+-------------------------------------------------------------------------------------------------------
datname | franzydb
query | select datname, query, wait_event, wait_event_type from pg_stat_activity where datname = 'franzydb';
wait_event |
wait_event_type |
-[ RECORD 2 ]---+-------------------------------------------------------------------------------------------------------
datname | franzydb
query | +
| copy scuola (id,nome,tipo_codice,tipo,comune,provincia) FROM STDIN
wait_event | ClientRead
wait_event_type | Client
franzydb=# select command, bytes_processed, bytes_total, tuples_processed from pg_stat_progress_copy ;
-[ RECORD 1 ]----+----------
command | COPY FROM
bytes_processed | 0
bytes_total | 0
tuples_processed | 0
On the SQLite3 side, the table it is trying to copy (scuola) is:
sqlite> SELECT SUM("pgsize") FROM "dbstat" WHERE name='scuola';
3235840
If I run pgloader with -d, the point where it hangs is:
024-11-07T11:13:07.621044+01:00 INFO COPY ON ERROR STOP
2024-11-07T11:13:07.657044+01:00 DEBUG CONNECTED TO #<PGLOADER.PGSQL:PGSQL-CONNECTION pgsql://franzy@rachel:5432/franzydb {1005B5A703}>
2024-11-07T11:13:07.657044+01:00 DEBUG SET client_encoding TO 'utf8'
2024-11-07T11:13:07.657044+01:00 DEBUG SET work_mem TO '64MB'
2024-11-07T11:13:07.658044+01:00 DEBUG SET maintenance_work_mem TO '512 MB'
2024-11-07T11:13:07.658044+01:00 DEBUG SET application_name TO 'pgloader'
2024-11-07T11:13:07.659044+01:00 INFO pgsql:copy-rows-from-queue[0]: scuola (id nome tipo_codice tipo comune
provincia)
and no other messages can be found in the logs.
Considering that there is an error launched on tbale maturita, while the COPY is active on another table, I tried to search for such a value causing the error, without any success:
% sqlite3 -line db/db.sqlite3 'select * from maturita;' | grep "25d0" | wc -l
0
On the PostgreSQL side, around the point where pgloader hangs, I find:
CET [32805]: [17] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.048 ms bind <unnamed>: select version()
CET [32805]: [18] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.033 ms execute <unnamed>: select version()
CET [32805]: [19] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.005 ms parse <unnamed>: BEGIN
CET [32805]: [20] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.002 ms bind <unnamed>: BEGIN
CET [32805]: [21] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.003 ms execute <unnamed>: BEGIN
CET [32805]: [22] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 47.217 ms statement:
copy maturita (id,studente_id,anno,voto_massimo,voto,lode,titolo,scuola_id) FROM STDIN
CET [32805]: [23] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.010 ms parse <unnamed>: COMMIT
CET [32805]: [24] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.004 ms bind <unnamed>: COMMIT
CET [32805]: [25] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.147 ms execute <unnamed>: COMMIT
CET [32805]: [26] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.005 ms parse <unnamed>: ROLLBACK
CET [32805]: [27] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.003 ms bind <unnamed>: ROLLBACK
CET [32805]: [28] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 WARNING: there is no transaction in progress
CET [32805]: [29] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.082 ms execute <unnamed>: ROLLBACK
CET [32805]: [30] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: disconnection: session time: 0:00:00.063 user=franzy database=franzydb host=192.168.222.1 port=57646
CET [32806]: [1] user=[unknown],db=[unknown],app=[unknown],client=192.168.222.1 LOG: connection received: host=192.168.222.1 port=57660
CET [32806]: [2] user=franzy,db=franzydb,app=[unknown],client=192.168.222.1 LOG: connection authenticated: identity="franzy" method=scram-sha-256 (/postgres/16/data/pg_hba.conf:128)
CET [32806]: [3] user=franzy,db=franzydb,app=[unknown],client=192.168.222.1 LOG: connection authorized: user=franzy database=franzydb application_name=postmodern-default
CET [32806]: [4] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.063 ms parse <unnamed>: SET client_encoding TO 'utf8'
CET [32806]: [5] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.014 ms bind <unnamed>: SET client_encoding TO 'utf8'
CET [32806]: [6] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.011 ms execute <unnamed>: SET client_encoding TO 'utf8'
CET [32806]: [7] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.009 ms parse <unnamed>: SET work_mem TO '64MB'
CET [32806]: [8] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.003 ms bind <unnamed>: SET work_mem TO '64MB'
CET [32806]: [9] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.005 ms execute <unnamed>: SET work_mem TO '64MB'
CET [32806]: [10] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.006 ms parse <unnamed>: SET maintenance_work_mem TO '512 MB'
CET [32806]: [11] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.002 ms bind <unnamed>: SET maintenance_work_mem TO '512 MB'
CET [32806]: [12] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.005 ms execute <unnamed>: SET maintenance_work_mem TO '512 MB'
CET [32806]: [13] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.005 ms parse <unnamed>: SET application_name TO 'pgloader'
CET [32806]: [14] user=franzy,db=franzydb,app=postmodern-default,client=192.168.222.1 LOG: duration: 0.003 ms bind <unnamed>: SET application_name TO 'pgloader'
CET [32806]: [15] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.004 ms execute <unnamed>: SET application_name TO 'pgloader'
CET [32806]: [16] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.141 ms parse <unnamed>: select version()
CET [32806]: [17] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.049 ms bind <unnamed>: select version()
CET [32806]: [18] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.007 ms execute <unnamed>: select version()
CET [32806]: [19] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.005 ms parse <unnamed>: BEGIN
CET [32806]: [20] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.003 ms bind <unnamed>: BEGIN
CET [32806]: [21] user=franzy,db=franzydb,app=pgloader,client=192.168.222.1 LOG: duration: 0.003 ms execute <unnamed>: BEGIN
I cannot spot the problem at all.
Activity
fluca1978 commentedon Nov 7, 2024
Update on the problem: I tested the same loading excluding the
scuolatable and the application loaded almost everything.Note that another table has a very similar problem, but:
pgloaderthis time continues;So, how can I find out what are the rows causing the problem, so that I can fix them?
Second, why is not
pgloaderstopping once I've configuredon error stopin the configuration file? Am I doing something wrong?fluca1978 commentedon Feb 27, 2025
I changed the
on error stopwith, on error resume nextand the process completes, but reporting errors.The final report shows something like:
where the first column is the number of errors. Is there a way to get an hint at lines that caused the error (I mean the source), so that I can fix them somehow?
fluca1978 commentedon Jun 22, 2026
Apparently there is still an issue: if I set the configuration
on error stopinstead ofresume nextthe loader locks.On the database size:
The configuration file is:
Fix premature COMMIT in stream-rows-to-copy under on error stop (#1748)
dimitri commentedon Jun 27, 2026
The root cause is now identified and fixed in PR #1748, merged to
main.What the PostgreSQL log reveals
Your server log shows the exact sequence the bug produces:
Root cause
In
stream-rows-to-copy(the code path used byon error stop),COMMITwas placed inside theunwind-protectcleanup, alongsideclose-db-writer:In Common Lisp,
handler-casehandlers run afterunwind-protectcleanup has finished. So when a data error occurred, the sequence was always: COMMIT (cleanup) → ROLLBACK (handler, now a no-op). The transaction was committed even on error, then the connection was left in an inconsistent state — which explains both the "no transaction in progress" warning and the subsequent hang on the next table's COPY.The fix
COMMITis moved to after theunwind-protectblock so it is only reached when the row loop andclose-db-writerboth complete without error. On any error, onlyclose-db-writerruns in the cleanup (cl-postgres leaves the connection in a clean SQL mode regardless), and thehandler-casehandler then correctly issuesROLLBACKagainst an active transaction.A secondary fix guards against a
TYPE-ERRORthat was raised whenstream-rowreturnednilfor a row it could not format — this masked the primary bug in certain error paths.To get the fix
Build pgloader from the current
mainbranch. A Debian package build should land in the next release.fluca1978 commentedon Jun 30, 2026
I can confirm this works!