Running your own database might sound like a silly thing to do these days. There are many hosted databases in the cloud. But, self-hosting is significantly cheaper. And it’s also probably easier than you think.
Deploy, install and manage a high-availabilty PostgreSQL cluster on Ubuntu Server
2. Install requirements
If you are new to Juju, consider our Getting Started with Juju tutorial.
3. Deploy PostgreSQL
$ juju deploy postgresql -n 2 --storage="pgdata=500G" --constraints="cores=4 mem=8G" Located charm "cs:postgresql-203". Deploying charm "cs:postgresql-203".
The options provided to the
juju deploy command are all that Juju needs to identify the correct.
-n 2asks for 2 “units” of the
postgresqlcharm to be deployed. When multiple units are deployed, PostgreSQL will be deployed with a failover secondary node.
--storagerequests that the cloud provider allocate storage that is not destroyed when instances are torn down. The
pgdatalabel is defined by the charm.
--constraints="cores=4 mem=8G"tells Juju to request instances from the cloud provider with at least 4 CPU cores and 8GB RAM each.
A constraint is a minimum requirement placed on Juju when it selects which instances to provision from the cloud provider.
Several application constraints are available. The most commonly used are are
Feel free to customise the application’s constraints. If you have low demands, then specify less memory that 8GB in the
4. Check configuration
postgresql charm has several configuration options. View them all via the
juju config command:
$ juju config postgresql
Useful options to consider are
admin_addressesto whitelist IP addresses that administrative tools such as pgAdmin can connect from
backup_scheduleto ensure that
pg_dumpbackups are performed with sufficient frequency, and
extra_pg_confto tune the database server.
5. (Optional) Expose PostgreSQL to the Internet
$ juju expose postgresql
Applications deployed with Juju within this model do not require Postgres to be exposed to the Internet.
Thank you for your feedback.