Starting Postgres automatically


#1

Do you have any suggestions as to how the PostgreSQL service could be started automatically?


Autostart services
Setting up PostgreSQL
#2

I’m not aware of any way to do this so I think you’ll need to start it manually. If you’re on a premium account and using a hot workspace then your server and database will stay running for a longer time than if you’re on a free account but it’s not an “always on” situation.


#3

You can add the startup command to ~/.profile.

See http://stackoverflow.com/questions/97137/how-do-you-run-a-script-on-login-in-nix

You would need to add it to each workspace that you use PostgreSQL in.


#4

IF you want to have the PostgreSQL start automatically:
Click on the Gear icon in Open files.
Check “Show Home in Favorites” and "Show Hidden Files"
in the top directory ~-. you will see the .profile (hidden file) open it for editing and put this in at bottom…

function checkstart {
service=1 if [[ ! (ps -ef | grep -v grep | grep “$service” | wc -l) > 0 ]]
then
sudo service $service start &
fi
}
checkstart postgresql

this will check if PostgreSQL database is running and if not it will start it whenever you launch a shell - which it does when you restart your workspace. Hope this helps!


#5

This did not work for me in my node workspace. However, I got PostgreSQL to start automatically using the following in my ~/.profile:
function checkstart {
service=$1
if ! pgrep -xc postgres > 0
then
echo "starting $service"
sudo service $service start
fi
}
checkstart postgresql

In addition, I could not get the ~/.profile to show up in the file tree so I used a terminal
cd ~
ls -la

I then scrolled through to find .profile
By clicking on the file name I could select ‘open’ to edit the file in the main editor.
Sometimes I have to click twice, first to ‘set the context’, then again to activate the context menu.