# Quick start

> Build the gateway and extension, create a tenant, start pgetcd and check readiness.

---

LLMS index: [llms.txt](/llms.txt)

---

This procedure builds `pgetcd` and `pg_etcd` from source and starts one tenant on an isolated PostgreSQL 18 primary with mutual TLS. For the supported RPCs and operating limits, see [Compatibility](/docs/etcd/compatibility/).

## Prerequisites {#prerequisites}

Prepare the `pgetcd` source checkout, Go `1.27.3`, a C compiler, and PostgreSQL `18.6` with its server headers and PGXS files (`pg_config`). You also need `psql`, `curl`, and permission to install extensions into the PostgreSQL instance.

Configure PostgreSQL TLS and authentication before starting:

- The PostgreSQL server certificate must match the host or IP address in `PGETCD_DSN`, and the gateway must trust its root CA.
- `pg_hba.conf` must allow the role `pgetcd_demo_gateway` to authenticate over TLS.
- Obtain the following mTLS certificates for the gateway and client (`SAN` is the certificate Subject Alternative Name):

| File | Requirement | Used by |
| --- | --- | --- |
| `server.crt`, `server.key` | Gateway server certificate and private key; SAN includes the endpoint IP or DNS name | Tenant JSON: `tls.certificate`, `tls.private_key` |
| `client-ca.crt` | CA that issued the tenant client certificate | Tenant JSON: `tls.client_ca` |
| `tenant-client.crt`, `tenant-client.key` | Client certificate and private key; URI SAN is `spiffe://pgetcd/tenant/demo` | `curl` and etcd clients |
| `server-ca.crt` | CA that issued the gateway server certificate | `curl --cacert` and client CA flags |
{.wide}

Keep private keys and generated credentials outside version control.

## Build the gateway and extension {#build}

Run these commands from the `pgetcd` checkout with `PG_CONFIG` pointing to your PostgreSQL 18 installation:

```bash
export PG_CONFIG=/path/to/postgresql/bin/pg_config
"$PG_CONFIG" --version
go version
mkdir -p .cache/docs-dev
go build -o .cache/docs-dev/pgetcd ./cmd/pgetcd
make -C extension PG_CONFIG="$PG_CONFIG"
make -C extension PG_CONFIG="$PG_CONFIG" install
.cache/docs-dev/pgetcd --version
```

The gateway binary is written to `.cache/docs-dev/pgetcd`. The extension installs `pg_etcd.so`, `pg_etcd.control`, and `pg_etcd--0.1.0.sql` into the directories selected by `PG_CONFIG`.

## Configure PostgreSQL {#postgresql}

Add `pg_etcd` to `shared_preload_libraries` in `postgresql.conf` and register the tenant database:

```ini
shared_preload_libraries = 'pg_etcd'
pg_etcd.databases = 'pgetcd_demo'
synchronous_commit = on
```

Keep `fsync` and `full_page_writes` enabled. Restart PostgreSQL so the `pg_etcd` preload launcher starts.

## Create the tenant database {#database}

Connect to PostgreSQL as an administrator, create the owner and gateway roles, install the extension, and grant access only to the four public SQL ABI functions:

```sql
CREATE ROLE pgetcd_owner NOLOGIN NOSUPERUSER;
CREATE ROLE pgetcd_demo_gateway LOGIN NOSUPERUSER
  NOCREATEDB NOCREATEROLE NOREPLICATION;
CREATE DATABASE pgetcd_demo;
\connect pgetcd_demo
CREATE EXTENSION pg_etcd;
REVOKE ALL ON DATABASE pgetcd_demo FROM PUBLIC;
GRANT CONNECT ON DATABASE pgetcd_demo
  TO pgetcd_owner, pgetcd_demo_gateway;
GRANT USAGE ON SCHEMA etcd TO pgetcd_demo_gateway;
GRANT EXECUTE ON FUNCTION
  etcd._abi(), etcd._execute(jsonb),
  etcd._tail_v2(bigint, integer), etcd._publication_barrier()
  TO pgetcd_demo_gateway;
```

Configure authentication for `pgetcd_demo_gateway` according to your instance policy (for example, client certificate authentication or `\password pgetcd_demo_gateway` in `psql`).

In the same session, read the database identity and readiness status:

```sql
BEGIN ISOLATION LEVEL READ COMMITTED;
SET LOCAL synchronous_commit = on;
SELECT etcd._execute(
  '{"abi":"1","method":"diag.status","request":{}}'::jsonb
);
COMMIT;
```

Verify the result in three steps:

1. Confirm that `COMMIT` completed without an error or a synchronous-replication cancellation warning.
2. Confirm that `response.ready`, `response.primary`, and `response.lease_ready` are all `true`.
3. Record `header.cluster_id` and `header.member_id` as decimal strings for the tenant configuration file.
{.steps}

If `response.ready` is `false`, inspect `response.not_ready_reasons`. If the Lease worker is still rebuilding, wait briefly and repeat the transaction. For other causes, see [Troubleshooting](/docs/etcd/operations/troubleshooting/#readiness).

## Start the gateway {#gateway}

Create `.cache/docs-dev/tenant.json` from the [tenant configuration example](/docs/etcd/reference/configuration/#tenant). Replace the placeholder `"1"` values for `cluster_id` and `member_id` with the decimal strings returned by `diag.status`, set `database` to `pgetcd_demo` and `role` to `pgetcd_demo_gateway`, and fill in your certificate paths.

Start `pgetcd` with `PGETCD_DSN` set to a `verify-full` TLS connection string:

```bash
export PGETCD_DSN='host=127.0.0.1 port=5432 dbname=pgetcd_demo user=pgetcd_demo_gateway sslmode=verify-full sslrootcert=/path/to/postgres-ca.crt'
.cache/docs-dev/pgetcd --tenant-config .cache/docs-dev/tenant.json
```

Append `sslcert` and `sslkey` to `PGETCD_DSN` if PostgreSQL requires SQL client certificates. Before opening its listeners, the gateway verifies the SQL ABI, persistent cluster and member identity, and Lease worker readiness.

In a second terminal, query the diagnostics readiness endpoint using the tenant client certificate:

```bash
curl --cacert /path/to/server-ca.crt \
  --cert /path/to/tenant-client.crt \
  --key /path/to/tenant-client.key \
  https://127.0.0.1:2381/readyz
```

A ready gateway returns `{"health":true}`. Continue with the [etcdctl and Go clientv3 tutorials](/docs/etcd/tutorial/).

> [!NOTE]
> This procedure was run end to end during the `v0.1.0-rc1` regression (commit `7e43446`) and again for `v0.1.0-rc2` (commit `81691bc`) on Linux amd64 with PostgreSQL 18.6, using certificate authentication and a synchronous standby.

---

Backlinks:

- [Build from source](/docs/etcd/operations/build/)
- [Configuration](/docs/etcd/reference/configuration/)
- [Tutorials](/docs/etcd/tutorial/)
- [Use etcdctl](/docs/etcd/tutorial/etcdctl/)
