> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a database manually

> Build a FlexiCapture database by hand: create a blank database, run the Description and DBInitFill scripts, assign a GUID, and add the first administrator.

You can build a FlexiCapture database by hand instead of creating it from the Administration and Monitoring Console. First create a blank database, and then initialize and configure it.

## Create a blank database

For Microsoft SQL Server or Oracle, create a blank database with your standard database management tools, and then continue with [Initialize and configure the database](#initialize-and-configure-the-database).

For PostgreSQL, create the database from the psql client:

1. Connect to the PostgreSQL server using an account with `CREATEDB`+`CREATEROLE` or `SUPERUSER` privileges:

   ```bash theme={null}
   psql -h srvname -U postgres
   ```

2. Create a user account with a predefined password and the right to log in to the server (here and in later steps, `rolename` is your user name):

   ```sql theme={null}
   CREATE ROLE rolename WITH ENCRYPTED PASSWORD 'rolepwd' LOGIN;
   ```

3. Create a new database (here and in later steps, `dbname` is your database name):

   ```sql theme={null}
   CREATE DATABASE dbname;
   ```

4. Grant the user the rights to connect to the database and to create temporary tables:

   ```sql theme={null}
   GRANT CONNECT, TEMPORARY ON DATABASE dbname TO rolename;
   ```

5. Prioritize the fc schema over the public schema:

   ```sql theme={null}
   ALTER DATABASE dbname SET search_path = "$user", fc, public;
   ```

6. Connect to the newly created database:

   ```sql theme={null}
   \c dbname
   ```

7. Create an fc schema and specify the user you created as its owner:

   ```sql theme={null}
   CREATE SCHEMA fc AUTHORIZATION rolename;
   ```

8. Create an ltree extension in the database:

   ```sql theme={null}
   CREATE EXTENSION IF NOT EXISTS ltree;
   ```

9. Disconnect from the PostgreSQL server.

<Warning>
  Carry out all subsequent operations on the PostgreSQL database under this user account.
</Warning>

## Initialize and configure the database

After the blank database exists, complete the following steps. Where the database engines differ, run the variant for your database.

1. Run the schema description script for your database:

   * Microsoft SQL Server: `Description.sql`
   * Oracle: `Description_Oracle.sql`
   * PostgreSQL: `Description_PostgreSQL.sql`

   By default, these scripts are in the `C:\inetpub\wwwroot\FlexiCapture12\Server` folder on the computer where the Application Server is installed.

2. Run the data initialization script for your database:

   * Microsoft SQL Server: `DBInitFill.sql`
   * Oracle: `DBInitFill_Oracle.sql`
   * PostgreSQL: `DBInitFill_PostgreSQL.sql`

3. Provide a unique identifier for the database.

   Microsoft SQL Server:

   ```sql theme={null}
   INSERT INTO dbo.Settings( Name, Value, ProjectId, BatchTypeId, UserId, Workstation, RoleId, ProcessingStage) VALUES ('DatabaseGUID', NEWID(), NULL, NULL, NULL, NULL, NULL, NULL )
   ```

   PostgreSQL:

   ```sql theme={null}
   INSERT INTO Settings (Name, Value)
   VALUES ('DatabaseGUID', upper(md5(clock_timestamp()::text)::uuid::text));
   ```

4. Add the first user.

   Microsoft SQL Server:

   ```sql theme={null}
   INSERT INTO principal (Name, FullName, EMail, PasswordHash, PasswordReset) values (N'Login', N'FullName', N'email', '', 0)
   ```

   PostgreSQL:

   ```sql theme={null}
   INSERT INTO Principal (Name, FullName, Email, PasswordHash, PasswordReset) values ('Login', 'FullName', 'email', '', false);
   ```

   Where:

   * **Login** — The login the user will use. Specify the login of the Windows user that will open the Administration and Monitoring Console when connecting to the database.
   * **FullName** — The full name of the user as displayed in their profile.
   * **Email** — The user's email address.

5. Specify the system administrator roles for the new user.

   Microsoft SQL Server:

   ```sql theme={null}
   INSERT INTO principalpermission (PrincipalId, RoleType, IsAllowed) values (1, 10, 1);
   ```

   PostgreSQL:

   ```sql theme={null}
   INSERT INTO principalpermission (PrincipalId, RoleType, IsAllowed) values (1, 10, true);
   ```

6. Connect to the newly created database using the Administration and Monitoring Console.

For details about the permissions an account needs to create and configure a database, see [Create a database](/flexi-capture/admin-guide/create-database).
