Creating a Metadata Repository in Linux OS

To create a repository on the PostgreSQL server on Linux OS:

  1. Download the Scheme.sql file with repository source data.

  2. Create the Pg_cr.sh script with the specified parameters in contents:

export USERNAME = <PostgreSQL user name>;
export PGPASSWORD = <user password>;
export ROLE = <user role>;
export SERVER = <DBMS server address>;
export PORT = <DBMS server port>;
export DBNAME = <database name>;
export DBPASSWORD = <database user password>;
export FILENAME = scheme.sql; // path to the file with repository source data
psql --host=$SERVER --port $PORT --username $USERNAME --dbname postgres --no-password -c "\\x" -c "select pg_terminate_backend(pid) from pg_stat_activity where datname = '${DBNAME}';";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname postgres --no-password -c "\\x" -c "drop database IF EXISTS \"${DBNAME}\";";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname postgres --no-password -c "\\x" -c "DROP ROLE IF EXISTS \"${ROLE}\";";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname postgres --no-password -c "\\x" -c "CREATE ROLE \"${ROLE}\" LOGIN ENCRYPTED PASSWORD '${DBPASSWORD}' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname postgres --no-password -c "\\x" -c "ALTER ROLE \"${ROLE}\" SET lo_compat_privileges='on';";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname postgres --no-password -c "\\x" -c "CREATE DATABASE \"${DBNAME}\" WITH OWNER = \"${ROLE}\" ENCODING = 'UTF8' TABLESPACE = pg_default  LC_COLLATE = default LC_CTYPE = default CONNECTION LIMIT = -1;";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname postgres --no-password -c "\\x" -c "GRANT ALL ON DATABASE \"${DBNAME}\" TO \"${ROLE}\";";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "CREATE FUNCTION loin (cstring) RETURNS lo AS 'oidin' LANGUAGE internal IMMUTABLE STRICT;";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "CREATE FUNCTION loout (lo) RETURNS cstring AS 'oidout' LANGUAGE internal IMMUTABLE STRICT;";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "CREATE FUNCTION lorecv (internal) RETURNS lo AS 'oidrecv' LANGUAGE internal IMMUTABLE STRICT;";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "CREATE FUNCTION losend (lo) RETURNS bytea AS 'oidsend' LANGUAGE internal IMMUTABLE STRICT;";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "CREATE TYPE lo ( INPUT = loin, OUTPUT = loout, RECEIVE = lorecv, SEND = losend, INTERNALLENGTH = 4, PASSEDBYVALUE );";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "CREATE CAST (lo AS oid) WITHOUT FUNCTION AS IMPLICIT;";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "CREATE CAST (oid AS lo) WITHOUT FUNCTION AS IMPLICIT;";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "CREATE OR REPLACE FUNCTION lo_manage() RETURNS pg_catalog.trigger AS '\$libdir/lo' LANGUAGE C;";
psql -U postgres -h $SERVER $DBNAME --single-transaction -f $FILENAME
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "grant all on all tables in schema public to \"${ROLE}\";";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "grant all on all SEQUENCES in schema public to \"${ROLE}\";";
psql --host=$SERVER --port $PORT --username $USERNAME --dbname $DBNAME --no-password -c "\\x" -c "grant all on all functions in schema public to \"${ROLE}\";";
  1. Run created script.

After executing the operations, metadata repository will be created in the specified DBMS.

See also:

Creating and Managing Metadata Repositories