Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions docs/using/database-instances.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Managing Database Instances




A Database instance is:


* A running Postgres server
* Bound to a specific host
* Identified by a node name (e.g. n1)
* Identified globally by an instance ID (eg 68f50878-44d2-4524-a823-e31bd478706d-n1-689qacsi)


Each instance maps to exactly one physical host, but a host can run multiple database instances as long as ports do not clash.


While a database is stable and persistent, database instances are runtime components with states that are not "identity-critical". This allows rolling updates, automatic failovers, and safe restarts.


Managing a database instance involves handling various operational needs throughout its lifecycle. For example, modifying certain POstgresSQL parameters can require a restart to take effect (eg shared_buffers), as the Control Plane does not automatically restart instances on a user’s behalf. Additionally, managing instances allows you to control costs by stopping unused development or test environments, troubleshoot issues when systems become unresponsive, and coordinate system updates in a controlled manner to minimize disruption to your applications.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo: "POstgresSQL" → "PostgreSQL".

Proposed fix
-Managing a database instance involves handling various operational needs throughout its lifecycle. For example, modifying certain POstgresSQL parameters can require a restart to take effect (eg shared_buffers), as the Control Plane does not automatically restart instances on a user's behalf. Additionally, managing instances allows you to control costs by stopping unused development or test environments, troubleshoot issues when systems become unresponsive, and coordinate system updates in a controlled manner to minimize disruption to your applications.
+Managing a database instance involves handling various operational needs throughout its lifecycle. For example, modifying certain PostgreSQL parameters can require a restart to take effect (e.g., shared_buffers), as the Control Plane does not automatically restart instances on a user's behalf. Additionally, managing instances allows you to control costs by stopping unused development or test environments, troubleshoot issues when systems become unresponsive, and coordinate system updates in a controlled manner to minimize disruption to your applications.

Also note: "eg" should be "e.g.," (with periods and comma) for proper abbreviation formatting, appearing both here and on line 12.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Managing a database instance involves handling various operational needs throughout its lifecycle. For example, modifying certain POstgresSQL parameters can require a restart to take effect (eg shared_buffers), as the Control Plane does not automatically restart instances on a users behalf. Additionally, managing instances allows you to control costs by stopping unused development or test environments, troubleshoot issues when systems become unresponsive, and coordinate system updates in a controlled manner to minimize disruption to your applications.
Managing a database instance involves handling various operational needs throughout its lifecycle. For example, modifying certain PostgreSQL parameters can require a restart to take effect (e.g., shared_buffers), as the Control Plane does not automatically restart instances on a user's behalf. Additionally, managing instances allows you to control costs by stopping unused development or test environments, troubleshoot issues when systems become unresponsive, and coordinate system updates in a controlled manner to minimize disruption to your applications.
🧰 Tools
🪛 LanguageTool

[grammar] ~21-~21: Ensure spelling is correct
Context: ...fecycle. For example, modifying certain POstgresSQL parameters can require a restart to tak...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🤖 Prompt for AI Agents
In @docs/using/database-instances.md at line 21, Fix the typos in the sentence
that reads "modifying certain POstgresSQL parameters... (eg shared_buffers)" by
changing "POstgresSQL" to "PostgreSQL" and replacing "eg" with the proper
abbreviation "e.g.,", and apply the same "eg" → "e.g.," correction to the
earlier occurrence on line 12; update the sentence text so it reads e.g.,
"(e.g., shared_buffers)" and "PostgreSQL" exactly as spelled.





## Monitoring Instances


To access important information about a database instance, call the GetDatabase endpoint by specifying its database ID as shown below for a database "example".


In the following example, the `curl` command retrieves database information for a database named "example":


```sh
curl http://host-3:3000/v1/databases/example
```


The endpoint will return the following information pertaining to the database.


* `created_at`: Timestamp when the database was created
* `id`: Database identifier
* `instances`: Array of instance objects containing instance-specific information
* `spec`: Database specification
* `state`: Current state of the database
* `updated_at`: Timestamp of last update


### Finding Instance IDs


The `instances` array contains information about a database instance, specifically:


* `id`: The instance identifier (e.g., `storefront-n1-689qacsi`) required for instance operations
* `node_name`: The node this instance belongs to (e.g., `n1`)
* `host_id`: The host where this instance runs
* `state`: Current operational state of the instance
* `postgres`: Postgres status information, including the `pending_restart` field which indicates if a configuration change requires a restart
* `connection_info`: Connection details for this instance
* `created_at` and `updated_at`: Instance timestamps


The `pending_restart` field within the `postgres` object is particularly important—when `true`, it signals that configuration changes have been applied that will only take effect after the instance is restarted.


### Instance States


Postgres instances can be in different states as a result of database operations (start/stop/restart/etc):


* `available`
* `starting`
* `stopping`
* `restarting`
* `failed`
* `error`
* `unknown`

Comment on lines +69 to +82
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing "stopped" state in the enumeration.

The "Stopping Instances" section (line 90, 93) references a stopped state, but it's not included in this list of possible instance states.

Proposed fix
 * `available`
 * `starting`
 * `stopping`
+* `stopped`
 * `restarting`
 * `failed`
 * `error`
 * `unknown`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### Instance States
Postgres instances can be in different states as a result of database operations (start/stop/restart/etc):
* `available`
* `starting`
* `stopping`
* `restarting`
* `failed`
* `error`
* `unknown`
### Instance States
Postgres instances can be in different states as a result of database operations (start/stop/restart/etc):
* `available`
* `starting`
* `stopping`
* `stopped`
* `restarting`
* `failed`
* `error`
* `unknown`
🤖 Prompt for AI Agents
In @docs/using/database-instances.md around lines 69 - 82, The instance states
list is missing the `stopped` state referenced elsewhere; update the "Instance
States" enumeration under the "Instance States" heading to include `stopped`
alongside `available`, `starting`, `stopping`, `restarting`, `failed`, `error`,
and `unknown` so it matches the references in the "Stopping Instances" section
and the rest of the document.


## Stopping Instances


Stopping an instance shuts down the Postgres process for that specific instance by scaling it to zero. The instance no longer accepts connections and is taken out of service, but its data and configuration are preserved. Other instances in the same database can continue running. As Stop Instance removes a database instance from service without deleting it, it can be used to isolate an instance not currently in use but that is expected to be restarted later.


* Transition: available → stopping → stopped
* Port remains reserved for this instance
* Other instances remain unaffected
* A stopped instance continues to appear under list-databases with state: "stopped"


In the following example, the `curl` command stops an instance named "n1" for a database named "example":


```sh
curl http://host-3:3000/v1/databases/example/instances/n1/stop
```
Comment on lines +96 to +101
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the database-instances.md file to see the actual examples
head -150 docs/using/database-instances.md | tail -70

Repository: pgEdge/control-plane

Length of output: 2646


🏁 Script executed:

# Also get lines around 115-119 to see the start example
sed -n '90,130p' docs/using/database-instances.md

Repository: pgEdge/control-plane

Length of output: 1598


🏁 Script executed:

# Look for API route definitions or implementation that handles instance operations
fd -e go -e js -e ts -e py | xargs grep -l "instances.*stop\|instances.*start" 2>/dev/null | head -20

Repository: pgEdge/control-plane

Length of output: 289


🏁 Script executed:

# Search for API endpoint definitions that handle instance operations
rg "instances.*\{.*\}/stop|instances.*\{.*\}/start" --type yaml --type json --type go

Repository: pgEdge/control-plane

Length of output: 1693


🏁 Script executed:

# Search for node_name handling in instance operations
rg "node_name|node.name" api/apiv1/ --type go | grep -i "stop\|start\|instance" | head -20

Repository: pgEdge/control-plane

Length of output: 996


🏁 Script executed:

# Check the actual handler implementations for instance operations
fd -e go -path "*/workflows/*" | xargs grep -l "stop.*instance\|StopInstance" 2>/dev/null | head -5

Repository: pgEdge/control-plane

Length of output: 232


🏁 Script executed:

# Look for route parameter handling
rg "instance_id|instanceID" api/apiv1/design/api.go -A 3 -B 3

Repository: pgEdge/control-plane

Length of output: 3228


Fix multiple API endpoint inconsistencies in instance operation examples.

The documentation has several errors in the API endpoint examples:

  1. Stop example: Uses incorrect HTTP method (GET instead of POST), wrong path (/stop instead of /stop-instance), and wrong identifier format (n1 instead of full instance ID)
  2. Start and restart examples: Use incorrect path suffixes (/start and /restart instead of /start-instance and /restart-instance)

All three operations must use POST method and the full instance ID (e.g., example-n1-689qacsi). The node_name field (like n1) is metadata only and cannot be used in URL paths.

Proposed fixes

Stop example:

-In the following example, the `curl` command stops an instance named "n1" for a database named "example":
+In the following example, the `curl` command stops an instance with ID "example-n1-689qacsi" for a database named "example":


```sh
-curl http://host-3:3000/v1/databases/example/instances/n1/stop
+curl -X POST http://host-3:3000/v1/databases/example/instances/example-n1-689qacsi/stop-instance

Start example:
```diff
```sh
-curl -X POST http://host-3:3000/v1/databases/example/instances/example-n1-689qacsi/start
+curl -X POST http://host-3:3000/v1/databases/example/instances/example-n1-689qacsi/start-instance

Restart example:
```diff
```sh
-curl -X POST http://host-3:3000/v1/databases/example/instances/example-n1-689qacsi/restart
+curl -X POST http://host-3:3000/v1/databases/example/instances/example-n1-689qacsi/restart-instance

</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

In @docs/using/database-instances.md around lines 96 - 101, Update the instance
operation examples to use POST and the correct endpoint suffixes and full
instance IDs: replace the stop example curl with a POST to
/v1/databases/example/instances/example-n1-689qacsi/stop-instance (not GET
/.../n1/stop), and change the start and restart examples to POST to
/v1/databases/example/instances/example-n1-689qacsi/start-instance and
/v1/databases/example/instances/example-n1-689qacsi/restart-instance
respectively; ensure the examples use the full instance ID (example-n1-689qacsi)
rather than the node_name (n1) and include -X POST in each curl invocation.


</details>

<!-- fingerprinting:phantom:poseidon:ocelot -->

<!-- This is an auto-generated comment by CodeRabbit -->

Comment on lines +99 to +101
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add explicit HTTP method for stop operation.

The stop operation modifies state and should use POST (like start and restart). Without -X POST, curl defaults to GET, which may not work correctly for this endpoint.

Proposed fix
-curl http://host-3:3000/v1/databases/example/instances/n1/stop
+curl -X POST http://host-3:3000/v1/databases/example/instances/n1/stop
🤖 Prompt for AI Agents
In @docs/using/database-instances.md around lines 99 - 101, The curl example for
stopping an instance currently omits the HTTP method and will default to GET;
update the example to explicitly use POST (e.g., add -X POST) so the stop
operation mirrors the start/restart examples and correctly invokes the
state-changing endpoint (/v1/databases/example/instances/n1/stop).



## Starting Instances


Starts a specific instance within a database by scaling it back up. This operation is only valid when the instance is in a stopped state. A successful start instance operation will transition an instance state from stopped to starting to available, allowing normal access and use to continue and restarting any activities.


* Transition: stopped → starting → available
* Retains same port as before stop
* Fails if port is already taken (a safety check)


In the following example, the `curl` command starts an instance with ID "example-n1-689qacsi" for a database named "example":


```sh
curl -X POST http://host-3:3000/v1/databases/example/instances/example-n1-689qacsi/start
```


## Restarting Instances


Restarting an instance stops and then starts the same Postgres instance, either immediately or at a scheduled time. This is typically used to recover from errors or apply changes that require a restart. The instance keeps its identity and data, but experiences a brief downtime during the restart.


* If no scheduled_at is provided → restart immediately.
* Transition: available → restarting → available
* Restart is blocked if: No configuration changes require a restart, Another update is in progress, or Instance is not stable


In the following example, the `curl` command restarts an instance with ID "example-n1-689qacsi" for a database named "example":


```sh
curl -X POST http://host-3:3000/v1/databases/example/instances/example-n1-689qacsi/restart
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ nav:
- Backup & Restore: using/backup-restore.md
- Tasks & Logs: using/tasks-logs.md
- Read Replicas: using/read-replicas.md
- Managing Database Instances: using/database-instances.md
- Deleting a Database: using/delete-db.md
- Migrating a Database: using/migrate-db.md
- API:
Expand Down