Nacho Nacho - 7 months ago 20
Linux Question

PostgreSQL population process dies if I cancel the terminal from which I have called it?

I have created a DB called 'enws'. I'm using a python script '' for populating the DB from data stored at a file called 'xSparse.txt'. I'm very new to linux and postgresql and I'd like to know whether the population script, called from remote terminal (ssh), dies if I cancel such a terminal from which I have called it? See below my setting:

python -cs --file xSparse.txt --dbname enws

If I look at htop, even when the work terminal is down some related processes (I think) are still running:

enws [local] INSERT
enws [local] CREATE TABLE waiting -cs --file xSparse.txt --dbname enws

Also I'm trying to know what processes to kill in order to start again and if I need to clear the DB in that case.

Thank you guys.


Use a screen for scripts which take a long time to run.

sudo apt-get install screen

Some screen useful commands:

screen -S foo //create a new screen called foo
screen -ls //List all your screens
screen -r foo //resume your foo screen

To exit a screen press ctrl+A and then D To when you are inside a screen, if you type "exit", it will exit your current screen. So, login with ssh, type something like:

screen -S script
python -cs --file xSparse.txt --dbname enws
ctrl+a ...d

And screen -r script to reopen it.

It allows you to run whatever you want, and it will keep running even closing the terminal.

If your script is sending a query to a database and you exit the script, the database will perform the query anyway, because once the script sends the query to the database, the only way to stop it is killing it from sql or shutting down the database service (or turning off the computer)