Let $(\Omega,\mathcal A,\mu)$ be a measure space, $p,q\ge1$ with $p^{-1}+q^{-1}=1$ and $f:\Omega\to\mathbb R$ be $\mathcal A$-measurable with $$\int|fg|\:{\rm d}\mu<\infty\;\;\;\text{for all }g\in L^q(\mu)\tag1.$$ By $(1)$, $$L^q(\mu)\ni g\mapsto fg\tag2$$ is a bounded linear fuctional and hence there is a unique $\tilde f\in L^p(\mu)$ with $$(f-\tilde f)g=0\;\;\;\text{for all }g\in L^q(\mu)\tag3.$$
Can we conclude that $f=\tilde f$?
EDIT: As we can see from this answer, we need to impose further assumptions; but which do we really need?
Assume that we don't have $f = \tilde{f}$ almost everywhere. Then there is an $\varepsilon > 0$ and $E$ with finite measure at least $\varepsilon$ such that $|f-\tilde{f}| \geq \varepsilon$ on $E$. Then $g = \operatorname{sign}(f- \tilde{f}) \chi_E$ is in $L^q(\mu)$ and $$\int (f-\tilde{f}) g d\mu \geq \varepsilon^2 > 0.$$
Edit: Note that this answer assumes that the measure space is semifinite to assume pathological examples. At the point it was written, it was clear from discussion with OP that this is what OP wants.