Posts

Showing posts with the label Bash

One billion records table in Postgresql

I have a simple table in Postgersql database with character key. CREATE TABLE public.zero_hids ( hexblock character(32) COLLATE pg_catalog."default" NOT NULL, hid bigint, CONSTRAINT zero_hids_pkey PRIMARY KEY (hexblock) USING INDEX TABLESPACE alcal ) It is required to insert into this table 1000000000 unique records by loading from CSV file. We can split this file to 5 parts by 200 millions each and insert it from command line: !/bin/bash time psql --port=5433 -d db1 -c "COPY zero_hids FROM '/tmp/table0.csv' delimiter AS ',' HEADER CSV" ... time psql --port=5433 -d db1 -c "COPY zero_hids FROM '/tmp/table4.csv' delimiter AS ',' HEADER CSV" Size of each part is around 9 Gigabytes. Allowed memory limit to Postgresql is 32Gb. Here is results: COPY 200000000 real 55m16.461s user 0m0.040s sys 0m0.008s COPY 200000000 real 89m48.861s user 0m0.048s sys 0m0.016s COPY 200000000 real 202m21.283s user 0m0.04...

Installing and using a free GeoIP database

Today's article is about install and update GeoIP database on Debian-like systems, integrate it with PHP and Apache. To install GeoIP on Debian 8 or Ubuntu 16.04 simple run this command: apt-get install geoip-database geoip-database-extra Now you have a GeoIP installed. But databases are obsolete. To update GeoIP databases, find data files on your system: dpkg -L geoip-database | grep GeoIP.dat You get a path like /usr/share/GeoIP/ Go to that directory and download updates: wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz Unpack files with replace old: gzip -df *.gz Rename GeoLiteCity.dat to GeoIPCity.dat: mv -f GeoLiteCity.dat GeoIPCity.dat You can put all these commands into one bash file (e.g. geoipupd.sh ) to run as single command: #!/bin/bash cd /usr/share/GeoIP/ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz wget ...