diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c
index cff49ba..8e6c525 100644
--- a/src/backend/catalog/storage.c
+++ b/src/backend/catalog/storage.c
@@ -27,8 +27,10 @@
 #include "catalog/catalog.h"
 #include "catalog/storage.h"
 #include "catalog/storage_xlog.h"
+#include "postmaster/autovacuum.h"
 #include "storage/freespace.h"
 #include "storage/smgr.h"
+#include "storage/lock.h"
 #include "utils/memutils.h"
 #include "utils/rel.h"
 
@@ -269,6 +271,7 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
 		xlrec.blkno = nblocks;
 		xlrec.rnode = rel->rd_node;
 		xlrec.flags = SMGR_TRUNCATE_ALL;
+		xlrec.isautovacuum = IsAutoVacuumWorkerProcess();
 
 		XLogBeginInsert();
 		XLogRegisterData((char *) &xlrec, sizeof(xlrec));
@@ -495,6 +498,16 @@ smgr_redo(XLogReaderState *record)
 		xl_smgr_truncate *xlrec = (xl_smgr_truncate *) XLogRecGetData(record);
 		SMgrRelation reln;
 		Relation	rel;
+		bool		isautovacuum = false;
+
+		/*
+		 * Check iff truncation made by autovacuum, then take Exclusive lock
+		 * because previously AccessEclusive lock was blocked from master to
+		 * let long transctions run on replica.
+		 * NB: do it only InHotStandby
+		 */
+		if (InHotStandby)
+			isautovacuum = xlrec->isautovacuum;
 
 		reln = smgropen(xlrec->rnode, InvalidBackendId);
 
@@ -525,10 +538,29 @@ smgr_redo(XLogReaderState *record)
 
 		if ((xlrec->flags & SMGR_TRUNCATE_HEAP) != 0)
 		{
+			LOCKTAG		locktag;
+
+			/*
+			 * If the value isautovacuum is true, then we assume that truncate
+			 * wal was formed by the autovacuum and we ourselves have to take
+			 * ExclusiveLock on the relation, because we didn`t apply
+			 * AccessExclusiveLock from master to let long transactions to work
+			 * on relica.
+			 */
+			if (isautovacuum)
+			{
+				/* Behave like LockRelationForExtension */
+				SET_LOCKTAG_RELATION_EXTEND(locktag, xlrec->rnode.dbNode, xlrec->rnode.relNode);
+				(void) LockAcquire(&locktag, ExclusiveLock, false, false);
+			}
+
 			smgrtruncate(reln, MAIN_FORKNUM, xlrec->blkno);
 
 			/* Also tell xlogutils.c about it */
 			XLogTruncateRelation(xlrec->rnode, MAIN_FORKNUM, xlrec->blkno);
+
+			if (isautovacuum)
+				LockRelease(&locktag, ExclusiveLock, true);
 		}
 
 		/* Truncate FSM and VM too */
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index 44ed209..34fbd30 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -23,6 +23,7 @@
 #include "access/xloginsert.h"
 #include "miscadmin.h"
 #include "pgstat.h"
+#include "postmaster/autovacuum.h"
 #include "storage/bufmgr.h"
 #include "storage/lmgr.h"
 #include "storage/proc.h"
@@ -37,6 +38,7 @@
 int			vacuum_defer_cleanup_age;
 int			max_standby_archive_delay = 30 * 1000;
 int			max_standby_streaming_delay = 30 * 1000;
+extern bool hot_standby_feedback;
 
 static List *RecoveryLockList;
 
@@ -805,10 +807,17 @@ standby_redo(XLogReaderState *record)
 		xl_standby_locks *xlrec = (xl_standby_locks *) XLogRecGetData(record);
 		int			i;
 
-		for (i = 0; i < xlrec->nlocks; i++)
-			StandbyAcquireAccessExclusiveLock(xlrec->locks[i].xid,
-											  xlrec->locks[i].dbOid,
-											  xlrec->locks[i].relOid);
+		/*
+		 * If this xlog standby lock was formed by autovacuum, then ignore it
+		 * because this can cause a lock conflict with a long transaction
+		 * running on the replica and kill transaction or its backend.
+		 * It is importent on hot standbys with hot_standby_feedback = on
+		 */
+		if (!xlrec->isautovacuum)
+			for (i = 0; i < xlrec->nlocks; i++)
+				StandbyAcquireAccessExclusiveLock(xlrec->locks[i].xid,
+												  xlrec->locks[i].dbOid,
+												  xlrec->locks[i].relOid);
 	}
 	else if (info == XLOG_RUNNING_XACTS)
 	{
@@ -1031,6 +1040,7 @@ LogAccessExclusiveLocks(int nlocks, xl_standby_lock *locks)
 	xl_standby_locks xlrec;
 
 	xlrec.nlocks = nlocks;
+	xlrec.isautovacuum = IsAutoVacuumWorkerProcess();
 
 	XLogBeginInsert();
 	XLogRegisterData((char *) &xlrec, offsetof(xl_standby_locks, locks));
diff --git a/src/include/catalog/storage_xlog.h b/src/include/catalog/storage_xlog.h
index 5738071..049de955 100644
--- a/src/include/catalog/storage_xlog.h
+++ b/src/include/catalog/storage_xlog.h
@@ -48,6 +48,7 @@ typedef struct xl_smgr_truncate
 	BlockNumber blkno;
 	RelFileNode rnode;
 	int			flags;
+	bool		isautovacuum;	/* mark that autovacuum called xl_smgr_truncate */
 } xl_smgr_truncate;
 
 extern void log_smgrcreate(RelFileNode *rnode, ForkNumber forkNum);
diff --git a/src/include/storage/standbydefs.h b/src/include/storage/standbydefs.h
index bb61448..dadceb3 100644
--- a/src/include/storage/standbydefs.h
+++ b/src/include/storage/standbydefs.h
@@ -38,6 +38,7 @@ extern void standby_desc_invalidations(StringInfo buf,
 typedef struct xl_standby_locks
 {
 	int			nlocks;			/* number of entries in locks array */
+	bool		isautovacuum;	/* mark that autovacuum called xl_standby_locks */
 	xl_standby_lock locks[FLEXIBLE_ARRAY_MEMBER];
 } xl_standby_locks;
 
