Waii's Kubernetes deployment requires a running Postgres server. Please make sure that the server is accessible from the K8s cluster and that you have the connection string for the server.
Next, you need to create a database for the Waii service:
IMPORTANT: You should use one RDS database for one Waii instance. (You can still use the same RDS instance, but you should create a new database for each Waii instance.)
Basic setup
Here're basic steps to setup Postgres database for Waii self-hosted:
CREATE DATABASE `<waii_db>`;
And enable the pgvector extension for the particular database:
CREATE EXTENSION vector;
Advanced setup for user permissions
If you want to limit the user permissions, you can create a new user and grant the necessary permissions. At a minimum, the user should have the following permissions:
- Be able to read from tables
- Be able to create/alter/delete tables/schemas
Waii service only need permissions within the <waii_db>
database, so you don't need to grant permissions to any other databases.
-- Create the new user
CREATE USER waii_user WITH PASSWORD 'your_password_here';
-- Grant connect permission on the database
GRANT CONNECT ON DATABASE `<waii_db>` TO waii_user;
-- Connect to the specific database
\c `<waii_db>`
-- Grant usage on the public schema
GRANT USAGE ON SCHEMA public TO waii_user;
-- Grant read permissions on all existing tables in the public schema
GRANT SELECT ON ALL TABLES IN SCHEMA public TO waii_user;
-- Grant permissions to create, update, and delete tables and schemas
GRANT CREATE ON SCHEMA public TO waii_user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO waii_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO waii_user;
-- Grant permission to create new schemas
GRANT CREATE ON DATABASE `<waii_db>` TO waii_user; [Replace `<waii_db>` with your db name]
-- Set default privileges for future tables and sequences
ALTER DEFAULT PRIVILEGES FOR USER waii_user IN SCHEMA public
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO waii_user;
ALTER DEFAULT PRIVILEGES FOR USER waii_user IN SCHEMA public
GRANT ALL ON SEQUENCES TO waii_user;
-- Grant usage on all existing schemas
GRANT USAGE ON SCHEMA public TO waii_user;
Sanity test
Run sanity check before the next step (Make sure you have psql installed), this is not required by the Waii service.
Sanity test for PGVector related operations
psql postgresql://username:password@host:port/`<waii_db>` [Replace `<waii_db>` with your db name]
=> create table test_vector (id serial primary key, vector vector);
=> select * from public.test_vector;
You should be able to see something like:
id | vector
----+--------
(0 rows)
Drop the table after the test:
=> drop table test_vector;
Sanity test for user permissions to the database
-- psql -U waii_user -d `<waii_db>`
-- Start transaction
BEGIN;
-- 1. Create a new schema
CREATE SCHEMA test_schema;
-- 2. Create a table in the new schema
CREATE TABLE test_schema.test_table (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 3. Insert rows into the table
INSERT INTO test_schema.test_table (name) VALUES
('Test Row 1'),
('Test Row 2'),
('Test Row 3');
-- 4. Select from the table
SELECT * FROM test_schema.test_table;
-- 5. Update a row
UPDATE test_schema.test_table SET name = 'Updated Row' WHERE id = 1;
-- 6. Delete a row
DELETE FROM test_schema.test_table WHERE id = 3;
-- 7. Select again to verify update and delete
SELECT * FROM test_schema.test_table;
-- Clean up (comment out if you want to keep the test schema and table)
DROP SCHEMA test_schema CASCADE;
-- Commit transaction
COMMIT;
-- Check current user => it should be waii_user
SELECT current_user;