sorry, I still confused ,as we have already created the publication "pub_test" , but during database runtime, function GetPublicationByName() does not get system catalog cache, Is there any mechanism that could make system catalog expand or shrink?
The system catalog doesn't expand or shrink in this case but rather it uses a snapshot to check the visibility of rows present. Here, we use historic snapshots to check the visibility of the publication row. Even though it is present in the catalog, it won't be visible, so you are getting an error. Here, the snapshot is built from WAL starting from the point where you created a slot. As the publication is created after Insert when you are trying to decode Insert, the required publication is not visible and hence you are getting the error. You might want to read src/backend/replication/logical/snapbuild.c to understand how the required snapshots are built from WAL.