Speed insert or update query running on a large postgres table

Got this tip from the this post:

Problem

When you run a large query (insert/update) on a huge table with several indexes, these indexes can seriously slow the query execution.

Solution

With Postgresql it can be faster to disable the indexes before running the query and reindex all the table afterwards.

You can do it like this :

  1. Disable all table indexes
UPDATE pg_index
SET indisready=false
WHERE indrelid = (
    SELECT oid
    FROM pg_class
    WHERE relname='<TABLE_NAME>'
);
  1. Run your query
UPDATE <TABLE_NAME> SET ...;
  1. Re-enable all table indexes
UPDATE pg_index
SET indisready=true
WHERE indrelid = (
    SELECT oid
    FROM pg_class
    WHERE relname='<TABLE_NAME>'
);
  1. Re-index table

Edit Width of Thermal Receipt Jasper Report

Problem

Need to edit the dimensions of a thermal receipt that is used in cash point machines. The dimensions I got for the paper were 57X47X13. These dimensions are in mm.

The important thing to note is 57mm is the width.

Solution

Change the jrxml dimesions from Pixels to mm. Then Change the width of the report to 57mm.

Then edit the text fields dimensions accordingly.

Here’s a screenshot of the report:

thermal receipt on jasper reports
Thermal receipt on Jasper Reports

References

THERMAL ROLL 57X40X13MM

timedatectl

Problem

An ubuntu server 16.04 time was not being synchronized. Here was the error in the syslog:


timesyncd[26781]: Timed out waiting for reply from [2001:67c:1560:8003::c8]:123 (ntp.ubuntu.com)

 

When I checked time timedatectl NTP synchronized was showing as off and when I tried to turn it on it wasn’t changing state.


# timedatectl
Local time: Mon 2019-01-21 10:49:54 XXX
Universal time: Mon 2019-01-21 07:49:54 UTC
RTC time: Mon 2019-01-21 07:53:45
Time zone: One/Two (XXX, +0300)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no

# timedatectl set-ntp on
# timedatectl
Local time: Mon 2019-01-21 10:54:41 XXX
Universal time: Mon 2019-01-21 07:54:41 UTC
RTC time: Mon 2019-01-21 07:58:32
Time zone: One/Two (XXX, +0300)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no
# timedatectl
Local time: Mon 2019-01-21 11:12:14 XXX
Universal time: Mon 2019-01-21 08:12:14 UTC
RTC time: Mon 2019-01-21 08:16:05
Time zone: One/Two (XXX, +0300)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no

Solution

I needed to update the firewall settings and allow outgoing traffic for the ntp port. After this the time was synchronized:


systemd[1185]: Time has been changed

Then when you check timedatectl


# timedatectl
Local time: Mon 2019-01-21 11:35:04 XXX
Universal time: Mon 2019-01-21 08:35:04 UTC
RTC time: Mon 2019-01-21 08:35:04
Time zone: One/Two (XXX, +0300)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no

References

How To Set Up Time Synchronization on Ubuntu 16.04

How to use ntpdate behind a proxy?

Remove unused docker images containers network and volumes

Problem

Unused containers, images, volumes, networks were taking up alot of disc space

Solution

  • You can decide first decide to clear out containers that have been stopped that is those with their status as exited:
List exited containers
$ docker ps -a -f status=exited > 2019-01-15

Remove

$ docker rm $(docker ps -a -f status=exited -q)

You can also delete containers with status created:

$ docker ps -a -f status=created
$ docker rm $(docker ps -a -f status=created -q)
f5eb19a737e2
e849f8700371

Now you can delete all the unused (dangling) images, volumes, networks:

$ docker system prune
WARNING! This will remove:
- all stopped containers
- all volumes not used by at least one container
- all networks not used by at least one container
- all dangling images
Are you sure you want to continue? [y/N] y

Total reclaimed space: 14.92GB

References

How To Remove Docker Images, Containers, and Volumes