Skip to content

Instantly share code, notes, and snippets.

@dbanetto
Last active April 23, 2018 08:50
Show Gist options
  • Save dbanetto/eb7b941740af6e993f1cb1ddeb95beca to your computer and use it in GitHub Desktop.
Save dbanetto/eb7b941740af6e993f1cb1ddeb95beca to your computer and use it in GitHub Desktop.
Systemd service to lazily start postgres when you need it

Lazy Postgres

A systemd service to activate postgresql only when you need it

Install

requires: Postgresql and Systemd

  • create postgresql.socket into /usr/lib/systemd/system
  • run sudo systemctl enable postgresql.socket to enable the socket service
  • Optional run sudo systemctl start postgresql.socket to use it this boot

Uninstall

  • run sudo systemctl disable postgresql.socket to disable the socket service
  • run sudo systemctl stop postgresql.socket to stop the listening socket

Cavets

  • slow 1st time usage, may even fail 1st connection attempt
  • ListenStream needs to point to where postgres would be, e.g. port 5432 or a socket file. Config is for Arch Linux
[Socket]
ListenStream=/run/postgresql/.s.PGSQL.5432
[Install]
WantedBy=sockets.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment