Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
solovieff committed Aug 15, 2020
0 parents commit 024c617
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
logs
db
backup

*.pid
*.pid.lock
*.iml
.idea

31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM postgres:12

LABEL maintainer='Andrey Solovyev [email protected]'

RUN apt-get update
RUN apt-get -y install postgresql-server-dev-12 libsybdb5 freetds-dev freetds-common make gcc git libaio1 libaio-dev

WORKDIR /root

RUN git clone https://github.com/tds-fdw/tds_fdw.git
WORKDIR tds_fdw
RUN make USE_PGXS=1
RUN make USE_PGXS=1 install

WORKDIR /root

RUN apt-get clean && \
rm -rf /var/cache/apt/* /var/lib/apt/lists/*

#ENTRYPOINT ["/docker-entrypoint.sh"]
RUN mkdir /pg
RUN mkdir /backup
RUN mkdir /logs
RUN chown postgres:postgres /logs
RUN chown postgres:postgres /pg
RUN chown postgres:postgres /backup

WORKDIR /pg

EXPOSE 5432
#CMD ["postgres"]
3 changes: 3 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WARNING !!!! All additional components and libraries are provided by their vendors free sources 'as is',
and should be used with respect to their licenses.
---
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.1'

services:

postgres:
build: .
restart: always
container_name: "postgres"
volumes:
- ./db:/var/lib/postgresql/data/ # persist data even if container shuts down
- ./logs:/logs
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
- ./backup:/backup
ports:
- 5430:5432
networks:
- share-network
environment:
POSTGRES_PASSWORD: 1234
#below is not used and should be set directly.
SQL_SERVER_USER: sqlserv_user
SQL_SERVER_PASSWORD: sqlserv_password
SQL_SERVER_HOST: 192.168.0.32
SQL_SERVER_PORT: 1433
SQL_SERVER_DB: db_name
SQL_SERVER_SCHEMA: sql_srv_schema_name
command: postgres -c logging_collector=on -c log_destination=stderr -c log_directory=../logs
networks:
share-network:
28 changes: 28 additions & 0 deletions init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- creating new db user
CREATE ROLE db_admin LOGIN PASSWORD 'db_admin';
-- creating new db
CREATE DATABASE db_name owner db_admin ENCODING 'UTF8';

\c db_name

CREATE EXTENSION tds_fdw;
-- env vars can not be passed here directly
-- TODO: sh script to init with env vars
CREATE SERVER mssql_svr
FOREIGN DATA WRAPPER tds_fdw
OPTIONS (servername '192.168.0.32', port '1433', database 'db_to_use', tds_version '7.1');

GRANT USAGE ON FOREIGN SERVER mssql_svr TO db_admin;

CREATE USER MAPPING FOR db_admin
SERVER mssql_svr
OPTIONS (username 'sql_srv_username', password 'sql_srv_password');

CREATE USER MAPPING FOR postgres
SERVER mssql_svr
OPTIONS (username 'sql_srv_username', password 'sql_srv_password');

IMPORT FOREIGN SCHEMA sql_srv_schema_name
FROM SERVER mssql_svr
INTO public
OPTIONS (import_default 'true');
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Postgres 12 with tds_fdw extension to access MSSQL server DB directly using foreign tables. Includes basic commands to create and configure foreign server.

Created on base of: https://hub.docker.com/r/muritiku/postgres-tds

See TODO in sql script. You have to manually change SQL server values there.
3 changes: 3 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mkdir db
mkdir logs
docker-compose up --build -d postgres
1 change: 1 addition & 0 deletions stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose down

0 comments on commit 024c617

Please sign in to comment.