Useful shortcuts for vi editor

Showing posts with label log. Show all posts
Showing posts with label log. Show all posts

Monday, 8 October 2018

How to find/follow postgresql server logs?

-> Check log level from config file
# cat /var/lib/pgsql/data/postgresql.conf
e.g.
log_min_messages= 'ERROR' (default value)
(options; DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC)

-> Determine log directory name (via postgres user)
$ psql
postgres=# show log_directory;
e.g. pg_log

-> Determine data directory name (via postgres user)
$ psql
postgres=# show data_directory;
e.g. /var/lib/pgsql/data

-> Determine log file name (via postgres user)
$ psql
postgres=# show log_filename;
e.g. postgresql-%a.log (%a will be "day" of the week)
e.g. postgresql-%a-%H.log (%H will be "hour" of the day)

-> Check log rotation age of the log files
postgres=# show log_rotation_age;
e.g. 1d (1d means one day)
* The database system generate log files daily
e.g. 1h (1h means one hour)
* The database system generate log files hourly

Eventually, the log path could be like this;
e.g. 
# ls /var/lib/pgsql/data/pg_log/postgresql-Mon.log
# ls /var/lib/pgsql/data/pg_log/postgresql-Mon-07.log

-> To follow the logs by tail
e.g.
# tail -100f /var/lib/pgsql/data/pg_log/postgresql-Mon.log
# tail -100f /var/lib/pgsql/data/pg_log/postgresql-Mon-07.log

Ref: https://www.postgresql.org/docs/9.5/static/runtime-config-logging.html

Thursday, 9 August 2018

How to install/configure/run ansible?

-> Set hostname
# hostnamectl set-hostname ansible_host

-> Add remote hosts into /etc/hosts file
# vi /etc/hosts
10.10.10.2 remote_host_2
10.10.10.3 remote_host_3

-> Generate ssh key without passphase
# ssh-keygen

-> Install ssh key into remote servers
# ssh-copy-id remote_host_2
# ssh-copy-id remote_host_3

-> Install ansible rpm packages
# yum install ansible

-> Add remote hosts as nodes into /etc/ansible/hosts file
# vi /etc/ansible/hosts
[remote_hosts]
remote_host_2
remote_host_3

-> Prepare an ansible playbook in /etc/ansible/
# vi my_very_first_playbook.yml
# example playbook
- name: Run the role for me 
  hosts: remote_hosts
  roles:
  - example-role

-> Prepare a role for the playbook in /etc/ansible/roles/example-role/
# vi main.yml
- name: checking Command Scheduler service
  service: 
   name=crond.service
   state=started

-> Run the playbook in /etc/ansible/
# ansible-playbook my_very_first_playbook.yml
or
# ansible-playbook -i hosts my_very_first_playbook.yml
(i -> inventory, its default location is /etc/ansible/hosts)

-> To check the ansible logs
# tail -f /var/log/ansible.log