PostgreSQL
This guide shows you how to use PostgreSQL, a powerful, open source object-relational database system.
To run it, follow these steps:
-
Install the
kraft
CLI tool and a container runtime engine, e.g. Docker. -
Clone the
examples
repository andcd
into theexamples/postgres/
directory:
Code
Make sure to log into Unikraft Cloud by setting your token and a metro close to you.
We use fra0
(Frankfurt, ๐ฉ๐ช) in this guide:
Code
When done, invoke the following command to deploy this application on Unikraft Cloud:
Code
The output shows the instance URL and other details:
Code
In this case, the instance name is postgres-saan9
and the service young-thunder-fbafrsxj
.
They are different for each run.
If you use port 5432/tls as per the example above you can now directly connect to postgres:
Code
Use the unikraft
password at the password prompt.
You should see output similar to:
Code
Use SQL and psql
commands for your work.
Idle Scale-to-Zero
This example uses the idle
scale-to-zero policy by default (see the labels
section in the Kraftfile
).
It means that the instance will scale-to-zero even in the presence of psql
connections.
To ensure that the instance is not put into standby even for long running queries (during which the connections are also idle), the PostgreSQL example makes use of scale-to-zero application support.
To this end, we load the pg_ukc_scaletozero
module into PostgreSQL, which suspends scale-to-zero during query processing.
You can see this in action by running SELECT pg_sleep(10);
and verifying that the instance keeps on running.
If you'd like to use a port other than 5432/tls
you'll need to use the kraft cloud tunnel
command to connect to PostgreSQL. See the tunneling guide for more information.
In addition, you need to explicitly disable scale-to-zero by either changing the label in the Kraftfile
or use --scale-to-zero off
in the deploy command.
At any point in time, you can list information about the instance:
Code
Code
When done, you can remove the instance:
Code
Using Volumes
You can use volumes for data persistence for you PostgreSQL instance.
For that you would first create a volume:
Code
Then start the PostgreSQL instance and mount that volume:
Code
Customize Your Deployment
Your deployment is a standard PostgreSQL installation. Customizing the deployment generally means providing a different environment.
An obvious one is to use a different database password when starting PostgreSQL.
For that you use a different POSTGRES_PASSWORD
environment variable when starting the PostgreSQL instance.
You could also a different location to mount your volume or set additional configuration options.
And, of course, you can use the PostgreSQL instance in conjunction with a frontend service, see the guide here. However, in that case make sure to disable scale-to-zero if you plan to use the DB internally.
Support for scale-to-zero for internal instances is coming soon.
Learn More
Use the --help
option for detailed information on using Unikraft Cloud:
Code
Or visit the CLI Reference.