Files
ubicloud/rhizome/postgres/bin/restart
Burak Yucesoy a259c4508e Postgres v0.1
This is the initial commit for PostgreSQL service. It contains bare minimums
to introduce PostgreSQL service. Currently, we only create a virtual machine,
install PostgreSQL binaries in it and do some basic configurations. In the
upcoming commits we will add things like UI, API support, HA, backup/restore,
firewall rules, DNS names, scaling up/down, certificates and many more. Even
though this is incomplete, it provides enough infrastructure to build on top
of it.

Here are few notable design decisions we made in this commit;
- We don't ask for database name, username or password from user. They will
all be created by default. Database name and username is postgres, password
will be auto generated at run-time.
- Corollary of above, we are giving superuser access to users. This might be
biggest divergence of our postgres service implementation from the incumbents
but it is not an unseen practice. There are numerous benefits of this; most
importantly, it gives more power to users, which could tilt decision to our
favor for users who want or need superuser access. Secondly, it makes our
implementation simpler; we don't need to implement special logic to support
role or extension creation. Users can do these things themselves without
needing us to provide special API/UI. On the flip side, it is possible to
shoot yourself on the foot with too much power, and thus create additional
support burden. I expect this to be rare occasion, but we might want to
consider our support model for such cases.
- We are also introducing a new concept, that is not just about postgres in
this commit; service projects. PostgreSQL service only exposes PostgreSQL
resource to user not VMs or public IP addresses it creates in the back end.
Those resources needs to live in somewhere. Service project is exactly that.
Each service will have their own account and project where they can keep
the backing resources. In this commit, we are creating one project for all
PostgreSQL services' resources, but after gathering more data, we might
change that in the future.

Currently there is no API or GUI interface. To be able to create PostgreSQL
resources, you need to set ENV["POSTGRES_SERVICE_PROJECT_ID"] in your .env.rb.

Then you can create new postgres database with this command;
Prog::Postgres::PostgresNexus.assemble(<project-id>, <location>, "test-pg-server", "standard-4", 100)

After it is ready, you can get the connection string like this;
Postgres::PostgresServer.first.connection_string
2023-09-26 11:29:18 +03:00

10 lines
299 B
Ruby
Executable File

#!/bin/env ruby
# frozen_string_literal: true
require_relative "../../common/lib/util"
# We don't change the user to postgres here. Instead we run the below
# command as root, because the cluster is running from systemd, and can
# only be restarted as root.
r "sudo pg_ctlcluster 16 main restart"