When managing Astronomer Software, there may be instances where you need to remove a specific user from the PostgreSQL database. This guide walks you through the process of deleting a user from the astronomer_houston
database using Kubernetes and PostgreSQL. The steps involve running a temporary PostgreSQL pod, connecting to the relevant database, identifying the user, and finally deleting them.
Prerequisites
Before we begin, make sure you have:
- Access to your Kubernetes cluster.
-
Namespace where Astronomer is installed (in this case, we'll assume it's
astronomer
). - kubectl CLI set up and authenticated.
- PostgreSQL credentials stored as Kubernetes secrets.
Step 1: Run a PostgreSQL Pod in Your Kubernetes Namespace
The first step is to run a temporary PostgreSQL pod within your Kubernetes namespace. This pod will use the bitnami/postgresql
image and automatically connect to the astronomer_houston
database.
Here’s how to run it:
Once the command runs, you'll enter the PostgreSQL interactive terminal (psql
).
If you don’t see the command prompt, try pressing Enter to initiate the session.
Step 2: Check the List of Databases
Now that you’re inside the psql
shell, you can list all available databases using the following command:
This will output something like:
Look for the astronomer_houston
database. If your release name is different, replace astronomer
with your actual release name.
Step 3: Switch to the astronomer_houston
Database
Since you’ll be working in the astronomer_houston
database, switch to it by running the following command:
If successful, you'll see a message like this:
Step 4: Set the Search Path
Next, ensure that the correct schema is being used by setting the search path. In Astronomer, the default schema is often named houston$default
. To set this, run:
This ensures that your queries target the right schema.
astronomer_houston=> set search_path="houston$default";
SET
Step 5: Find the User by Email
Before deleting the user, you need to find their unique user ID in the system. Suppose the user you want to delete has the email john.doe@example.com
. You can retrieve their ID with this query:
SELECT id FROM "User" where username = 'kalyanreddy.kasireddy@astronomer.io';
id
----------------------------
cm2a96zyk3098117cs95o1k5z4
(1 row)
This query will return the user's ID, which is required for the next step. For example:
Note the id
that’s returned.
Step 6: Delete the User
Now that you have the user’s ID, you can proceed with deleting the user from the database.
Run the following DELETE
command:
This will remove the user with the corresponding ID from the database. You should see confirmation of the deletion:
Step 7: Exit the PostgreSQL Pod
Once you’ve finished, you can exit the PostgreSQL pod by typing:
This will close the pod session and delete the temporary pod since we used the --rm
flag when running the pod initially.
Alternative setup: No access to Bitnami image
If you are unable to access the Bitnami image to create the Postgres Pod, you can replace Step 2 from the core steps with the following setup and proceed to Step 3.
1. Run the following command to retrieve the database access string. Copy the output for later in this setup.
kubectl get secret astronomer-bootstrap -o jsonpath='{.data.connection}' | base64 -d
2. Create a local file called new_pod.yaml
and copy the following YAML configuration into the file:
apiVersion: v1 kind: Pod metadata: name: postgres-client labels: app: postgres-client spec: containers: - image: postgres:latest command: - sleep - "3600" imagePullPolicy: IfNotPresent name: postgres-client restartPolicy: Always
3. Run the following command to apply the YAML file and create a new Pod in the Astronomer namespace:
kubectl apply -f path/new_pod.yml
4. Run the following commands to access the PostgreSQL client within the newly created pod:
kubectl exec -it postgres-client -- sh
apt update && apt install postgresql-client
psql <database-access-string>
\l
➜ Another recommendation was to remove the user from all teams first. After that, you should be able to delete the user from the UI or Houston API query.
To find the user ID. You can do this by running a users
query or using the command astro workspace user list
.
mutation removeUser {
removeUser(userUuid: "cl74qcu6821035814fg6tavm6iz") {
username
}
}
Comments
0 comments
Please sign in to leave a comment.