PgBadger report from AWS RDS log parsed not fully - postgresql

I use pgbadger as following:
pgbadger -p %t:%r:%u#%d:[%p]: postgresql.log
log_line_prefix are set for RDS and cannot be changed. Its same that i pass to pgbadger ( %t:%r:%u#%d:[%p]: )
When i launch pgbadger i get following stdout output.
[=======================> ] Parsed 52063631 bytes of 52063634 (100.00%), queries: 66116, events: 0
LOG: Ok, generating html report...
So it parsed queries, and it output i see most of stats. But in Top section i see wrong info. Time consuming queries and Slowest individual queries says "no dataset". And in Most frequent queries (N) all queries have all durations as 0 . See screenshot here : http://clip2net.com/s/3wUxfXg . And examples for query dont show any examples at all.
I checked postgresql log and duration is there. For example:
2016-04-13 22:00:02 UTC:blabla.com(43372):blabla#blabla:[20584]:LOG: statement: SELECT DISTINCT "reports2_report"."id", "reports2_report"."created", "reports2_report"."modified", "reports2_report"."data", "reports2_report"."person_info", "reports2_report"."status", "reports2_report"."source_profile_id", "reports2_report"."application_id", "reports2_report"."error_detail" FROM "reports2_report" INNER JOIN "reports2_reportsourceprofile" ON ( "reports2_report"."source_profile_id" = "reports2_reportsourceprofile"."id" ) INNER JOIN "reports2_reportsource" ON ( "reports2_reportsourceprofile"."report_source_id" = "reports2_reportsource"."id" ) INNER JOIN "applications_applicationdocument" ON ( "reports2_report"."application_id" = "applications_applicationdocument"."slug" ) WHERE ("reports2_reportsource"."identifier" = 'redridge_credit' AND "reports2_report"."application_id" = 'jqLoMe' AND ("reports2_report"."application_id" IN (SELECT DISTINCT V0."slug" FROM "applications_applicationdocument" V0 LEFT OUTER JOIN "auth_user" V1 ON ( V0."seller_id" = V1."id" ) LEFT OUTER JOIN "accounts_companymembership" V2 ON ( V1."id" = V2."user_id" ) LEFT OUTER JOIN "applications_applicationbundle" V5 ON ( V0."bundle_id" = V5."id" ) LEFT OUTER JOIN "applications_applicationbundle_sharees" V6 ON ( V5."id" = V6."applicationbundle_id" ) WHERE (V2."company_id" IN (SELECT U0."id" FROM "accounts_company" U0 WHERE (U0."lft" > 2 AND U0."tree_id" = 6 AND U0."rght" < 3)) OR V0."applicant_id" = 111827 OR V0."seller_id" = 111827 OR V6."user_id" = 111827)) OR "applications_applicationdocument"."seller_id" = 111827 OR "applications_applicationdocument"."applicant_id" = 111827 OR "reports2_reportsourceprofile"."user_id" = 111827)) ORDER BY "reports2_report"."created" DESC LIMIT 20
2016-04-13 22:00:02 UTC:blabla.com(43372):blabla#blabla:[20584]:LOG: duration: 517.047 ms
How to get PgBadger to generate full proper report?

It was due to log_statement = all instead of log_statement=none. log_min_duration_statement works only if log_statement = none

Related

Postgresql: Error missing FROM-clause entry for table

I have a query and I keep getting this a 'missing FROM-clase entry for table e, rx.rootentityid = rh.entityid1 AND rh.schoolid = e.schoolid'.
can anyone see the error in my code. My postgresql knowledge is very limited.
SELECT
eh.entityid1, eh.entityname1, eh.entityid2, eh.entityname2,
eh.entityid3, eh.entityname3, eh.entityid4, eh.entityname4,
eh.entityid5, eh.entityname5, eh.entityid6, eh.entityname6,
eh.entityid7, eh.entityname7, eh.schoolentityid, eh.schoolid,
eh.emiscode, eh.schoolname, rh.entityid1 AS reportentityid1,
rh.entityname1 AS reportentityname1, rh.entityid2 AS reportentityid2,
rh.entityname2 AS reportentityname2
FROM dbo.vwentityhierarchyname
JOIN dbo.entity AS eh
ON vwentityhierarchyname.entityid1 = eh.entityid AND eh.entitytypeid = 1
CROSS JOIN (SELECT
hd.rootentityid
FROM dbo.hierarchydefinition AS hd
JOIN dbo.entity AS e
ON hd.rootentityid = e.entityid
WHERE hd.relatedrootentityid = e.entityid AND hd.entitytypeid = 7 AND LOWER(e.name) SIMILAR TO LOWER('%Report Regions%')) AS rx
LEFT OUTER JOIN dbo.vwentityhierarchyname AS rh
ON rx.rootentityid = rh.entityid1 AND rh.schoolid = e.schoolid
WHERE eh.schoolid = par_SchoolID
ORDER BY eh.entityid1 DESC NULLS FIRST
LIMIT 1;
Thanks

change query from postgresql into oracle

how change this query from postgresql into oracle?
SELECT tbmm.tbmm_id,
tbmm.tbmm_email AS seller_mail,
'FB' AS seller_type,
concat(tbmm.tbmm_firstname, COALESCE(tbmm.tbmm_middlename),
COALESCE(tbmm.tbmm_lastname)) AS seller_owner_name,
tbmss.tbmss_name AS seller_store_name,
tbmss.tbmss_description AS seller_description,
tbmss.tbmss_phone AS seller_phone,
btrim(concat(COALESCE(tbmma.tbmma_addr1), COALESCE(tbmma.tbmma_addr2,
tbmma.tbmma_addr1), COALESCE(tbmma.tbmma_addr3, tbmma.tbmma_addr1),
COALESCE(tbmkc.tbmkct_nama), COALESCE(tbmkl.tbmkl_nama),
COALESCE(tbmma.tbmma_postcode, '0') AS seller_store_address,
tbmb.tbmb_name AS bank_name,
concat(tbmb.tbmb_name, COALESCE(tbmsd.tbmsd_bank_account_branch) AS
bank_desc,
tbmsd.tbmsd_bank_account_no AS bank_account_no,
tbmsd.tbmsd_bank_account_name AS bank_account_name,
tbmsd.tbmsd_no_id AS seller_id_card,
'F' AS flag_alfamind,
0 AS commision,
tbmm.tbmm_mage_entity_id,
tbmm.tbmm_update_date AS member_update_date,
tbmss.tbmss_update_date AS store_update_date,
tbmsd.tbmsd_update_date AS document_update_date,
tbmma.tbmma_update_date AS address_update_date
FROM coreapp.tb_master_member tbmm
JOIN coreapp.tb_master_seller_store tbmss ON tbmm.tbmm_id =
tbmss.tbmm_id
JOIN coreapp.tb_master_seller_document tbmsd ON tbmsd.tbmm_id =
tbmm.tbmm_id
JOIN coreapp.tb_master_bank tbmb ON tbmb.tbmb_id = tbmsd.tbmb_id
JOIN coreapp.tb_master_member_group tbmg ON tbmg.tbmm_id = tbmm.tbmm_id
LEFT JOIN coreapp.tb_master_member_address tbmma ON tbmma.tbmm_id =
tbmm.tbmm_id AND tbmma.tbmma_address_type = 140 AND tbmma.tbmma_status = 23
LEFT JOIN coreapp.tb_master_kecamatan tbmkc ON
tbmkc.tbmkct_kecamatan_id = tbmma.tbmkct_kecamatan_id
LEFT JOIN coreapp.tb_master_kelurahan tbmkl ON tbmkl.tbmkl_kelurahan_id
= tbmma.tbmkl_kelurahan_id
WHERE tbmg.tbmg_id = 4;
i have try to query on my sql developer but something error with query
now I'm just try until one day and still can't run

Optimizing Postgres query with timestamp filter

I have a query:
SELECT DISTINCT ON (analytics_staging_v2s.event_type, sent_email_v2s.recipient, sent_email_v2s.sent) sent_email_v2s.id, sent_email_v2s.user_id, analytics_staging_v2s.event_type, sent_email_v2s.campaign_id, sent_email_v2s.recipient, sent_email_v2s.sent, sent_email_v2s.stage, sent_email_v2s.sequence_id, people.role, people.company, people.first_name, people.last_name, sequences.name as sequence_name
FROM "sent_email_v2s"
LEFT JOIN analytics_staging_v2s ON sent_email_v2s.id = analytics_staging_v2s.sent_email_v2_id
JOIN people ON sent_email_v2s.person_id = people.id
JOIN sequences on sent_email_v2s.sequence_id = sequences.id
JOIN users ON sent_email_v2s.user_id = users.id
WHERE "sent_email_v2s"."status" = 1
AND "people"."person_type" = 0
AND (sent_email_v2s.sequence_id = 1888) AND (sent_email_v2s.sent >= '2016-03-18')
AND "users"."team_id" = 1
When I run EXPLAIN ANALYZE on it, I get:
Then, if I change that to the following (Just removing the (sent_email_v2s.sent >= '2016-03-18')) as follows:
SELECT DISTINCT ON (analytics_staging_v2s.event_type, sent_email_v2s.recipient, sent_email_v2s.sent) sent_email_v2s.id, sent_email_v2s.user_id, analytics_staging_v2s.event_type, sent_email_v2s.campaign_id, sent_email_v2s.recipient, sent_email_v2s.sent, sent_email_v2s.stage, sent_email_v2s.sequence_id, people.role, people.company, people.first_name, people.last_name, sequences.name as sequence_name
FROM "sent_email_v2s"
LEFT JOIN analytics_staging_v2s ON sent_email_v2s.id = analytics_staging_v2s.sent_email_v2_id
JOIN people ON sent_email_v2s.person_id = people.id
JOIN sequences on sent_email_v2s.sequence_id = sequences.id
JOIN users ON sent_email_v2s.user_id = users.id
WHERE "sent_email_v2s"."status" = 1
AND "people"."person_type" = 0
AND (sent_email_v2s.sequence_id = 1888) AND "users"."team_id" = 1
when I run EXPLAIN ANALYZE on this query, the results are:
EDIT:
The results above from today are about as I expected. When I ran this last night, however, the difference created by including the timestamp filter was about 100x slower (0.5s -> 59s). The EXPLAIN ANALYZE from last night showed all of the time increase to be attributed to the first unique/sort operation in the query plan above.
Could there be some kind of caching issue here? I am worried now that there might be something else going on (transiently) that might make this query take 100x longer since it happened at least once.
Any thoughts are appreciated!

Updating using subqueries sql server 2008

There are two update queries and 1st update query execute successfully but 2nd update query is not execute and show the following message:
Msg 512, Level 16, State 1, Line 10
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated.
1st update query:
update dbo.TblPrePostApproval
set
dbo.TblPrePostApproval.PAApprovedDate = (select dbo.TblMasterInfo.AppRefDate
from dbo.TblMasterInfo
Where dbo.TblMasterInfo.Appid = dbo.TblPrePostApproval.Appid),
dbo.TblPrePostApproval.PAApprovedTenor = '36',
dbo.TblPrePostApproval.PAApprovedAmt = (select dbo.TblMasterInfo.AppReqeustAmt
from dbo.TblMasterInfo
where dbo.TblPrePostApproval.Appid = dbo.TblMasterInfo.AppID),
dbo.TblPrePostApproval.PADisbBr = (select dbo.TblMasterInfo.AppSourceBrName
from dbo.TblMasterInfo
where dbo.TblPrePostApproval.Appid = dbo.TblMasterInfo.AppID)
2nd update query
update dbo.TblPrePostApproval
set
dbo.TblPrePostApproval.PAApprovedDate = (select dbo.TestPost.PADate
from dbo.TestPost
Where dbo.TestPost.Appid = dbo.TblPrePostApproval.Appid),
dbo.TblPrePostApproval.PAApprovedTenor = (select dbo.TestPost.PATenor
from dbo.TestPost
Where dbo.TestPost.Appid = dbo.TblPrePostApproval.Appid),
dbo.TblPrePostApproval.PAApprovedAmt = (select dbo.TestPost.PAAmt
from dbo.TestPost
where dbo.TestPost.Appid = dbo.TblPrePostApproval.AppID),
dbo.TblPrePostApproval.PADisbBr = (select dbo.TestPost.PABr
from dbo.TestPost
where dbo.TestPost.Appid = dbo.TblPrePostApproval.AppID)
Where is my problem? Pls any one suggest me.
One of your subqueries (I guess on line 10) is returning more than one row, so it can't check to see if it equals anything, because it's a set, not a value. Just change your query to be more specific. Try adding LIMIT 0, 1 to the end of the subqueries, or TOP (1) after the the SELECT in each subquery.
Why don't you use JOINs for your update? Much easier to read and understand!
Query #1:
UPDATE ppa
SET
PAApprovedDate = info.AppRefDate,
PAApprovedTenor = '36',
PAApprovedAmt = info.AppReqeustAmt,
PADisbBr = info.AppSourceBrName
FROM
dbo.TblPrePostApproval ppa
INNER JOIN
dbo.TblMasterInfo.TblMasterInfo info ON info.Appid = ppa.Appid
Query #2:
UPDATE ppa
SET
PAApprovedDate = tp.PADate,
PAApprovedTenor = tp.PATenor,
PAApprovedAmt = tp.PAAmt,
PADisbBr = tp.PABr
FROM
dbo.TblPrePostApproval ppa
INNER JOIN
dbo.TestPost tp ON tp.Appid = ppa.AppID

How to determine the size of a Full-Text Index on SQL Server 2008 R2?

I have a SQL 2008 R2 database with some tables on it having some of those tables a Full-Text Index defined. I'd like to know how to determine the size of the index of a specific table, in order to control and predict it's growth.
Is there a way of doing this?
The catalog view sys.fulltext_index_fragments keeps track of the size of each fragment, regardless of catalog, so you can take the SUM this way. This assumes the limitation of one full-text index per table is going to remain the case. The following query will get you the size of each full-text index in the database, again regardless of catalog, but you could use the WHERE clause if you only care about a specific table.
SELECT
[table] = OBJECT_SCHEMA_NAME(table_id) + '.' + OBJECT_NAME(table_id),
size_in_KB = CONVERT(DECIMAL(12,2), SUM(data_size/1024.0))
FROM sys.fulltext_index_fragments
-- WHERE table_id = OBJECT_ID('dbo.specific_table_name')
GROUP BY table_id;
Also note that if the count of fragments is high you might consider a reorganize.
If you are after a specific Catalogue
Use SSMS
- Clik on [Database] and expand the objects
- Click on [Storage]
- Right Click on {Specific Catalogue}
- Choose Propertie and click.
IN General TAB.. You will find the Catalogue Size = 'nn'
I use something similar to this (which will also calculate the size of XML-indexes, ... if present)
SELECT S.name,
SO.name,
SIT.internal_type_desc,
rows = CASE WHEN GROUPING(SIT.internal_type_desc) = 0 THEN SUM(SP.rows)
END,
TotalSpaceGB = SUM(SAU.total_pages) * 8 / 1048576.0,
UsedSpaceGB = SUM(SAU.used_pages) * 8 / 1048576.0,
UnusedSpaceGB = SUM(SAU.total_pages - SAU.used_pages) * 8 / 1048576.0,
TotalSpaceKB = SUM(SAU.total_pages) * 8,
UsedSpaceKB = SUM(SAU.used_pages) * 8,
UnusedSpaceKB = SUM(SAU.total_pages - SAU.used_pages) * 8
FROM sys.objects SO
INNER JOIN sys.schemas S ON S.schema_id = SO.schema_id
INNER JOIN sys.internal_tables SIT ON SIT.parent_object_id = SO.object_id
INNER JOIN sys.partitions SP ON SP.object_id = SIT.object_id
INNER JOIN sys.allocation_units SAU ON (SAU.type IN (1, 3)
AND SAU.container_id = SP.hobt_id)
OR (SAU.type = 2
AND SAU.container_id = SP.partition_id)
WHERE S.name = 'schema'
--AND SO.name IN ('TableName')
GROUP BY GROUPING SETS(
(S.name,
SO.name,
SIT.internal_type_desc),
(S.name, SO.name), (S.name), ())
ORDER BY S.name,
SO.name,
SIT.internal_type_desc;
This will generally give numbers higher than sys.fulltext_index_fragments, but when combined with the sys.partitions of the table, it will add up to the numbers returned from EXEC sys.sp_spaceused #objname = N'schema.TableName';.
Tested with SQL Server 2016, but documentation says it should be present since 2008.