Introduces a new Hugo shortcode, `includeRegion`, to allow embedding specific, tagged regions from source files directly into Markdown content. This helps maintain a single source of truth for code snippets and other repeated content, such as setup instructions, preventing duplication and simplifying updates across multiple quickstart guides. Demo PR: https://github.com/googleapis/genai-toolbox/pull/1179 --------- Co-authored-by: Anmol Shukla <shuklaanmol@google.com>
4.2 KiB
In this section, we will create a database, insert some data that needs to be accessed by our agent, and create a database user for Toolbox to connect with.
-
Connect to postgres using the
psqlcommand:psql -h 127.0.0.1 -U postgresHere,
postgresdenotes the default postgres superuser.{{< notice info >}}
Having trouble connecting?
- Password Prompt: If you are prompted for a password for the
postgresuser and do not know it (or a blank password doesn't work), your PostgreSQL installation might require a password or a different authentication method. FATAL: role "postgres" does not exist: This error means the defaultpostgressuperuser role isn't available under that name on your system.Connection refused: Ensure your PostgreSQL server is actually running. You can typically check withsudo systemctl status postgresqland start it withsudo systemctl start postgresqlon Linux systems.
Common Solution
For password issues or if the postgres role seems inaccessible directly, try
switching to the postgres operating system user first. This user often has
permission to connect without a password for local connections (this is called
peer authentication).
sudo -i -u postgres
psql -h 127.0.0.1
Once you are in the psql shell using this method, you can proceed with the
database creation steps below. Afterwards, type \q to exit psql, and then
exit to return to your normal user shell.
If desired, once connected to psql as the postgres OS user, you can set a
password for the postgres database user using: ALTER USER postgres WITH PASSWORD 'your_chosen_password';. This would allow direct connection with -U postgres and a password next time.
{{< /notice >}}
-
Create a new database and a new user:
{{< notice tip >}} For a real application, it's best to follow the principle of least permission and only grant the privileges your application needs. {{< /notice >}}
CREATE USER toolbox_user WITH PASSWORD 'my-password'; CREATE DATABASE toolbox_db; GRANT ALL PRIVILEGES ON DATABASE toolbox_db TO toolbox_user; ALTER DATABASE toolbox_db OWNER TO toolbox_user; -
End the database session:
\q(If you used
sudo -i -u postgresand thenpsql, remember you might also need to typeexitafter\qto leave thepostgresuser's shell session.) -
Connect to your database with your new user:
psql -h 127.0.0.1 -U toolbox_user -d toolbox_db -
Create a table using the following command:
CREATE TABLE hotels( id INTEGER NOT NULL PRIMARY KEY, name VARCHAR NOT NULL, location VARCHAR NOT NULL, price_tier VARCHAR NOT NULL, checkin_date DATE NOT NULL, checkout_date DATE NOT NULL, booked BIT NOT NULL ); -
Insert data into the table.
INSERT INTO hotels(id, name, location, price_tier, checkin_date, checkout_date, booked) VALUES (1, 'Hilton Basel', 'Basel', 'Luxury', '2024-04-22', '2024-04-20', B'0'), (2, 'Marriott Zurich', 'Zurich', 'Upscale', '2024-04-14', '2024-04-21', B'0'), (3, 'Hyatt Regency Basel', 'Basel', 'Upper Upscale', '2024-04-02', '2024-04-20', B'0'), (4, 'Radisson Blu Lucerne', 'Lucerne', 'Midscale', '2024-04-24', '2024-04-05', B'0'), (5, 'Best Western Bern', 'Bern', 'Upper Midscale', '2024-04-23', '2024-04-01', B'0'), (6, 'InterContinental Geneva', 'Geneva', 'Luxury', '2024-04-23', '2024-04-28', B'0'), (7, 'Sheraton Zurich', 'Zurich', 'Upper Upscale', '2024-04-27', '2024-04-02', B'0'), (8, 'Holiday Inn Basel', 'Basel', 'Upper Midscale', '2024-04-24', '2024-04-09', B'0'), (9, 'Courtyard Zurich', 'Zurich', 'Upscale', '2024-04-03', '2024-04-13', B'0'), (10, 'Comfort Inn Bern', 'Bern', 'Midscale', '2024-04-04', '2024-04-16', B'0'); -
End the database session:
\q