# Getting Started

1. Download the [latest release](https://github.com/dolthub/doltgresql/releases) of `doltgres`
2. Put `doltgres` on your `PATH`
3. Run `doltgres`. This will create a `postgres` user (with a password of `password`) and a `postgres` database in `~/doltgres/databases` (add the `--data-dir` argument or change the `DOLTGRES_DATA_DIR` environment variable to use a different directory).

```bash
$ doltgres
Successfully initialized dolt data repository.
Starting server with Config HP="localhost:5432"|T="28800000"|R="false"|L="info"|S="/tmp/mysql.sock"
```

4. Make sure you have Postgres version 15 or higher installed. I used Homebrew to install Postgres on my Mac. This requires I manually add `/opt/homebrew/opt/postgresql@15/bin` to my path. On Postgres version 14 or lower, `\` commands (i.e. `\d`, `\l`) do not yet work with Doltgres.

```
export PATH="/opt/homebrew/opt/postgresql@15/bin:$PATH"
```

5. Open a new terminal. Connect with the following command: `psql -h localhost -U postgres` and enter the password `password` when prompted. This will connect to the `postgres` database with the `postgres` user.

```bash
$ psql -h 127.0.0.1 -U postgres
Password for user postgres: 
psql (15.4 (Homebrew), server 15.0)
Type "help" for help.

postgres=>
```

6. Create a `getting_started` database. Create the `getting_started` example tables.

```sql
postgres=> create database getting_started;
--
(0 rows)

postgres=> \c getting_started;
psql (15.4 (Homebrew), server 15.0)
You are now connected to database "getting_started" as user "postgres".
getting_started=> create table employees (
    id int8,
    last_name text,
    first_name text,
    primary key(id));
--
(0 rows)

getting_started=> create table teams (
    id int8,
    team_name text,
    primary key(id));
--
(0 rows)

getting_started=> create table employees_teams(
    team_id int8,
    employee_id int8,
    primary key(team_id, employee_id),
    foreign key (team_id) references teams(id),
    foreign key (employee_id) references employees(id));
--
(0 rows)

getting_started=> \d
              List of relations
 Schema |      Name       | Type  |  Owner
--------+-----------------+-------+----------
 public | employees       | table | postgres
 public | employees_teams | table | postgres
 public | teams           | table | postgres
(3 rows)
```

7. Make a Dolt Commit.

```sql
getting_started=> select * from dolt_status;
   table_name           | staged |  status
------------------------+--------+-----------
 public.employees       | 0      | new table
 public.employees_teams | 0      | new table
 public.teams           | 0      | new table
(3 rows)

getting_started=> select dolt_add('teams', 'employees', 'employees_teams');
 status
--------
      0
(1 row)
getting_started=> select * from dolt_status;
   table_name           | staged |  status
------------------------+--------+-----------
 public.employees       | 1      | new table
 public.employees_teams | 1      | new table
 public.teams           | 1      | new table
(3 rows)

getting_started=> select dolt_commit('-m', 'Created initial schema');
               hash
----------------------------------
 peqq98e2dl5gscvfvic71e7j6ne34533
(1 row)
```

8. View the Dolt log.

```
getting_started=> select * from dolt_log;
           commit_hash            | committer |       email        |        date         |          message
----------------------------------+-----------+--------------------+---------------------+----------------------------
 peqq98e2dl5gscvfvic71e7j6ne34533 | postgres  | postgres@127.0.0.1 | 2023-11-01 22:08:04 | Created initial schema
 in7bk735qa6p6rv6i3s797jjem2pg4ru | timsehn   | tim@dolthub.com    | 2023-11-01 22:04:03 | Initialize data repository
(2 rows)
```

9. Continue with [Dolt Getting Started](https://docs.dolthub.com/introduction/getting-started/database#insert-some-data) to test out more Doltgres versioning functionality.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.doltgres.com/introduction/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
