Making postgresql logs in JSON format - postgresql

I am using postgresql 9.5 on ubuntu 16.04.
Is there any way in postgresql so that it's logs can be stored in JSON format ?
I need to send it to elasticsearch, that's why I need to make postgresql logs in JSON format.
I followed this tutorial, but did not quite understood that what and where it was asking me to make changes in the conf file.

PostgreSQL listens to their community and your voice is heard !
PostgreSQL 15 beta has been released on May 15th, 2022. PostgreSQL version 15 now supports the jsonlog logging format which is to be released in third quarter of 2022 .
You have to make the below change in the postgresql.conf file
log_destination = 'jsonlog'
The log output will be written to a file, making it the third type of destination of this kind, after stderr and csvlog.
You can send these generated json logs to elasticsearch or any application for further log aggergations.
Check here for more info
Update: PostgreSQL v15 is out now. You can now explore them here

PostgreSQL self doesn't support any other formats than plain text and CSV. When you need other formats, then you need to get somewhere (or write by self) special extension that is able to touch log API and format and push PostgreSQL logs. One extension was developed by Michael and it is described in mentioned link. Here is link to source code: https://github.com/michaelpq/pg_plugins/tree/master/jsonlog . You have to compile this extension like any other (PostgreSQL extension) - code is in C language, and then you can use it.

As I am understanding your problem statement is you want to push postgresql logs to Elasticsearch.
For this I would recommend to use filebeat where you can simple enable the PostgresSQL module and set the log path. Filebeat start reading logs file and push to Elasticsearch.
You can visualize your data from kibana with readymade dashboard. It is simple plug and play.

Related

PostgreSQL Chage Data Capture in Talend

I need to capture PostgreSQL changes and I would prefer if it is log based.
How does tpostgresqlCDC work? Is it log/trigger based?
Is this component available on Talend open studio for data integration suit? I know it is available on the big data version, but I can seem to find it in Talend open studio for data integration?
Except AS400 and Oracle, all Talend CDC - trigger based
plus:
it only in subscription version
at least in MySQL realisations - I found some wrong logic
opposite to MySQL it not so wide available, but You can try to check:
Bottledwater
wla2jjson
Debezium , main site
CDC + Kafka - give real flexibility

Icinga database cleanup

I am working in Icinga for performance data collection,
I have to clear all plugin data more than 30 days, how can I do this. I had some google searches does not help.
some references:
External Commands List
Database model
I am using:
RHEL os
icinga2 from source build
postgresql
Using NRPE for collecting remote server data
Is there any tool available to cleanup or any queries to delete all database entries older than 30 days?
http://docs.icinga.org/latest/en/configido.html#configido-ido2db
From the manual, it looks like your ido2db.cfg needs to be configured with the proper data:
max_systemcommands_age=43200
max_servicechecks_age=43200
max_hostchecks_age=43200
max_eventhandlers_age=43200
max_externalcommands_age=43200
max_logentries_age=43200
max_acknowledgements_age=43200
max_notifications_age=43200
max_contactnotifications_age=43200
max_contactnotificationmethods_age=43200
Also, make sure that trim_db_interval is set somewhat sane. The default of 3600 should be sufficient.
trim_db_interval=3600

Installing and setting up logstash

I need to use Logstash to parse data from custom log files (generated from the our application). I have a tomcat server and mongodb. After going through the documentation online, I'm still unclear as to how to use the different input sources. There is a community based mongoDB database, but I'm unclear as to how use it.
How can I set up/ where should I start to begin using logstash parse logs from files?

talend , mongoDB connection

I am facing a problem with mongo DB connection.
I have succefully imported tMongo components it to my Talend Open Studio 5.1.1 and by copying the mongo 1.3.jar file to lib/java folder, my Mongo DB jobs are running successfully, but the problem is even if I provide some fake server path(IP) and fake port for mongoDB, my job is running without an error and it is giving me 1 row with no data. and same goes with right IP and port.
How do I resolve it.
I think the connection is not working. As you must be knowing, mongoDB checks that the connection is actually working or not when you perform a query on it.
(Yeah, it doesn't check for a successful connection when you just connect to it ).
I would suggest to instead add the mongoDB components present in Talend for Big Data by following the steps below:
Components provided for MongoDB are :
tMongoDBInput, tMongoDBOutput, tMongoDBConnection etc.
Or you can Download the components from http://www.talendforge.org/exchange/ and search for Mongo instead of using Talend Big Data. But I would suggest use Talend for big Data for it.
The components will be zipped format , Unzip the same. In Talend Big data you will find the components in Component folder.
Copy these Unzipped Components to the installation Path of TOS.
C:TalendTOS_DI-Win32-r84309V5.1.1pluginsorg.talend.designer.components.localprovider_5.1.1.r84309components
Copy the mongo-1.3.jar file in the component folder into the C:TalendTOS_DI-Win32-r84309-V5.1.1libjava
In many systems you might not be able to see this file then go with ADMINISTRATOR priviliges.
optional for few systems——>>> Inside index.xml add
save index.xml
Restart TOS
Then you will be able to use them as normal components.
Cheers!
The reason for the Job running without any error could be due to the connection / meta-data you have used for the Mongo Connector. It doesn't is not possible for the job to run without any error even after giving fakepath.
I guess you might configured (re-modified) the repository connection but using a built-in meta data for component.

How to get PostgreSQl log

How can I get log information from PostgreSQl server?
I found ability to watch it in pgAdmin Tolls->ServerStatus. Is there a SQL way, or API, or consol way, to show content of log file(s)?
Thanks.
I am command line addict, so I prefer “console” way.
Where you find logs and what will be inside those depends on how you've configured your PostgreSQL cluster. This the first thing I change after creating a new cluster, so that I get all the information I need and in the expected location.
Please, review your $PGDATA/postgresql.conf file for your current settings and adjust them in the appropriate way.
The adminpack extension is the one providing the useful info behind pgAdmin3's server status functionality.