5. Find all pairs of positive integers $(a, b)$ such that
$$
a b+2=a^{3}+2 b .
$$
5. From the problem, we know
$$
\begin{array}{l}
b=\frac{a^{3}-2}{a-2}=\frac{a^{3}-8}{a-2}+\frac{6}{a-2} \\
=a^{2}+2 a+4+\frac{6}{a-2} \in \mathbf{Z}_{+} \\
\left.\Rightarrow \frac{6}{a-2} \in \mathbf{Z} \Rightarrow(a-2) \right\rvert\, 6 \\
\Rightarrow a-2=1,2,3,6,-1,-2,-3,-6 \text {. } \\
\end{array}
$$

After inspection, $a=3,4,5,8,1$.
Accordingly, $b=25,31,41,85,1$.
Therefore, the pairs $(a, b)$ are $(1,1),(3,25),(4$,
$31),(5,41),(8,85)$.