Skip to content

Postgres JSON import Settings

Benjamin Mayer edited this page May 29, 2022 · 5 revisions

Convert

Convert Json file to postgres statements

https://konbert.com/app/convert

Edit create table

Change datatype of taxId and add id column

CREATE TABLE IF NOT EXISTS "customer" (
"id" SERIAL PRIMARY KEY,
"givenName" TEXT NULL,
"familyName" TEXT NULL,
"birthName" TEXT NULL,
"gender" TEXT NULL,
"birthDate" TEXT NULL,
"height" INT NULL,
"eyecolor" TEXT NULL,
"email" TEXT NULL,
"taxId" TEXT NULL,
"address.addressCountry" TEXT NULL,
"address.addressLocality" TEXT NULL,
"address.postalCode" INT NULL,
"address.streetAddress" TEXT NULL,
"address.houseNumber" TEXT NULL,
"phoneNo" TEXT NULL,
"mobileNo" TEXT NULL,
"bankAccount.bank.city" TEXT NULL,
"bankAccount.bank.bankCode" INT NULL,
"bankAccount.bank.desc" TEXT NULL,
"bankAccount.bank.bic" TEXT NULL,
"bankAccount.iban" TEXT NULL,
"creditCard.number" TEXT NULL,
"creditCard.type" TEXT NULL,
"creditCard.cvc" INT NULL
);

Edit insert statement

added column names:

INSERT INTO customer ("givenName" ,
"familyName" ,
"birthName" ,
"gender" ,
"birthDate" ,
"height" ,
"eyecolor" ,
"email" ,
"taxId" ,
"address.addressCountry" ,
"address.addressLocality" ,
"address.postalCode" ,
"address.streetAddress" ,
"address.houseNumber" ,
"phoneNo" ,
"mobileNo" ,
"bankAccount.bank.city" ,
"bankAccount.bank.bankCode" ,
"bankAccount.bank.desc" ,
"bankAccount.bank.bic" ,
"bankAccount.iban" ,
"creditCard.number" ,
"creditCard.type" ,
"creditCard.cvc" ) VALUES

Change max connection settings

Inside the postgres docker container open the file /var/lib/pgsql/{version_number}/data/postgresql.conf and change the following 2 lines to the needed amount (increase buffer relative max connections)

max_connections = 1000
shared_buffers = 512MB

after that restart the docker container to apply the new settings

run docker image with:
sudo docker run --name postgres -e POSTGRES_DB=download_ms -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD='dbadmin!2020' -p 5432:5432 -v /data:/var/lib/postgresql/data -d postgres

connect to db inside docker container:
docker run -it --rm postgres psql -U postgres -h <container-ip>

to get docker container ip use:
docker network inspect bridge

Clone this wiki locally