The lie group $SO(p,q)$ has two connected components. The one proof I know uses the transitive action of the group on a two sheeted hyperboloid (can be found on Onishchik and Vinberg book).
I am very confident that we can arrive at the same result by inspecting the Cartan decomposition of $SO(p,q)$.
Recall the Cartan decomposition says in short that given a real Lie subgroup $G$ of $GL_n(\mathbb{C})$ and $K= \{ g \in G : g= (g^*)^{-1} \}$, then the natural map $$ K \times \mathfrak{h} \longrightarrow G$$ $$(k, X) \mapsto k \exp(X),$$ where $\mathfrak{h}$ is the space of all hermitian elements of the Lie algebra of $G$, is a diffeomorphism.
In the case of $O(p,q),$ which has 4 connected components, the Cartan decomposition tells us that $$O(p,q) \simeq O(p) \times O(q) \times \mathfrak{h}$$, where $\mathfrak{h}$ denotes the space of symmetric matrices. Hence, since $O(n)$ has two connected components, it follows $O(p,q)$ must have 4 connected components. This decomposition arises by noting that we can identify $K$ with $O(p) \times O(q)$.
Applying the same reasoning to $SO(p,q)$, I verified we can identify the set $K$ with $SO(p) \times SO(q)$. However, $SO(n)$ is connected, and therefore the product $SO(p) \times SO(q) \times \mathfrak{h}$ is also connected.
Something is clearly escaping me. What have I done wrong?
I think what went wrong is that for $SO(p,q)$ you cannot identify $K$ with $SO(p)\times SO(q)$, but with $S(O(p)\times O(q))=\{(A,B)\in O(p)\times O(q):\det(A)\det(B)=1\}$, which has two connected components. This is exactly the general version of the fact observed in the answer of @JohnHughes for $p=q=1$.