问题
I'm experiencing a strange issue when importing data into postgres. I have an import script that runs once daily at night via cronjob on a Linux OS (Linux 4.9.0-5-amd64 #1 SMP Debian 4.9.65-3+deb9u2 (2018-01-04) x86_64 GNU/Linux
). The process reads a file containing about 2 million rows and inserts these into a table in batches (batch size 25.000). This takes roughly 2 to 2.5 minutes, which is absolutely reasonable. The table has 3 indexes and meanwhile contains more than 130M rows. To increase the performance I declared the table as UNLOGGED
and disabled WAL
. From time to time I need to upgrade the system which requires a server restart. This somehow affects the database as the data import suddenly takes instead of minutes about 1 to 1.5 hours. I couldn't find out any reason for this. What's going wrong here, any ideas?
回答1:
This happened to me once. Don't really know why, but for me it was fixed after restarting the postgresql service. My thinking says that if you do not restart the service(even after a reboot), it seems postgres keeps its WAL (Write-Ahead Logging). By restarting the service everything cleans up, so everything runs as good as new again. But, perhaps there's another reason. Anyway, try restarting the service instead of rebooting or restart the service after reboot.
Read the question comments for more info or this link that @user35934 posted.
来源:https://stackoverflow.com/questions/48328237/postgres-9-6-inserts-very-slow-after-reboot